2011-01-27 88 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