2011-01-27 128 views
1


我需要在用戶按buttonIndex 1後顯示確認提醒,但如果我使用popViewcontrollerclickedButtonAtIndex它崩潰沒有錯誤。在clickedButtonAtIndex中顯示警報?

的問題是,

[self.navigationController popViewControllerAnimated:YES]; 

之前第二警報單擊名爲...

如何解決?

這是我的代碼:

- (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { 
    if (buttonIndex == 1) { 
     UIAlertView *alert = 
      [[UIAlertView alloc] initWithTitle:@"OK!" 
            message:@"Completed" 
            delegate:self 
        cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; 
      [alert show]; 
      [alert release]; 

      [self.navigationController popViewControllerAnimated:YES]; 
    } 
} 
+0

我曾把UIAlertView中的一個子類,只是因爲人們無法在觸摸屏上點擊。命名這個代表的這個傢伙在地獄裏有一個特別的地方。 – 2011-01-27 16:52:11

回答

3

設置兩個UIAlertViews的標籤屬性,分別爲1和2。然後,在委託方法中,使用if語句來檢查UIAlertView參數的標籤。

例子:

- (void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
{ 
    if (alertView.tag == 1) 
    { 
     //check the button index 
     //create and display the other alert view (set the tag property here to 2) 
    } 
    else if (alertView.tag == 2) 
    { 
     //pop the view controller 
    } 
} 
+0

救生員!非常感謝 – pqsk 2014-07-20 23:39:10