2014-01-20 16 views
0

我正在使用故事板。它有一個登錄VC,成功推向另一個VC。當用戶輸入憑證並單擊登錄按鈕時,它會打到服務器。我已經實現了所有包含與服務器在具有委託的單獨類中的邏輯。當我們得到迴應時,控制權轉到登錄VC中實現的委託方法。在代理方法中,如果狀態爲成功,則只有登錄VC必須被推入另一個VC。使用自定義代理實現條件性segue

在登錄VC

- (BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender 
{ 
    Util *util = [[Util alloc]init]; 
    util.delegate = self; 

    NSMutableDictionary *request = [[NSMutableDictionary alloc]init]; 
    [request setValue:uname.text forKey:@「username」]; 
    [request setValue:pwd.text forKey:@「password」]; 
    [util body:request]; 
} 

當服務器返回響應談到在登錄VC實現的委託方法

- (void)response:(NSDictionary *)response 
{ 
    //here i am going to check the status if it is success i will go to new VC else in same VC 
} 

在這裏我無法去到另一個VC,因爲我在我不應該執行使用標識符:方法。

回答

0

你爲什麼不叫

[self performSegueWithIdentifier:@"customerView" sender:self]; 
0

看起來你很可能觸發您的賽格瑞當登錄按鈕被竊聽。如果您需要等待Web服務的響應,則無法執行此操作。相反,嘗試將您的按鈕連接到發送您的登錄請求時的方法。當您收到您的回覆,你可以檢查用戶的登錄是有效的,然後編程執行你賽格瑞:

- (void)response:(NSDictionary *)response 
{ 
    if (something) // check if response is valid 
    { 
     [self performSegueWithIdentifier:@"YourSegueIdentifier" sender:self]; 
    } 
    else 
    { 
     // show error 
    } 
} 

這樣一來,你就不會需要實現shouldPerformSegueWithIdentifier:sender:可言。