扩展UIAlertView的功能?

时间:2011-06-02 06:03:02

标签: iphone objective-c xcode uialertview

我正在使用 UIAlertView 并显示消息 Peer Disconnected .Back地面工作/剩余代码正在运行而不会被忽略。有一个名为继续<的按钮/ strong>即可。我只需在单击继续按钮后才能处理剩余的代码。 而且我需要在取消按钮中退出我的应用程序click.can任何一个告诉我一个很好的方法来做到这一点。

我的代码是:

UIAlertView *alertView;  
alertView = [[UIAlertView alloc] initWithTitle:@"Peer Disconnected!" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:@"Continue", nil];
[alertView show];
[alertView release];

3 个答案:

答案 0 :(得分:1)

你可以调用下面解释的UIAlertView的委托方法......

 - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
 {
      if (buttonIndex == 0) {
          //Your Code   //For First Button
      } else if (buttonIndex == 1) {
          //Your Code   //For Second Button
      }
 }

请按此Link退出申请

答案 1 :(得分:1)

试试这个: -

UIAlertView *alertView;  
alertView = [[UIAlertView alloc] initWithTitle:@"Peer Disconnected!" message:nil delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:@"Continue", nil];
[alertView show];
[alertView release];


- (void)alertView:(UIAlertView *)alert didDismissWithButtonIndex:(NSInteger)buttonIndex
{   
    if(buttonIndex==0)
    {
NSLog(@"cancel clicked");
    }
    else if(buttonIndex==1)
    {
NSLog(@"continue clicked");
    }
    }

答案 2 :(得分:0)

UIAlertView *alertView;  
alertView = [[UIAlertView alloc] initWithTitle:@"Peer Disconnected!" message:nil delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Continue", nil];
[alertView show];
[alertView release];

实施此委托方法。

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if(buttonIndex == alertView.cancelButtonIndex) {
// Cancel operation...
}else if (buttonIndex == alertView.firstOtherButtonIndex) {
// Continue operation...
}
}