objective-c - IOS:停止 UIAlert 循环

标签 objective-c xcode ios uialertview

我有这个代码:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
      if(buttonIndex == 0)
      {

      }
      else if(buttonIndex == 1)
      {
           UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Danger" 
                                                        message:@"war"
                                                       delegate:self 
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles:nil];
    [alertView show];
    [alertView release];

      }
}

但是每次我按下这个 UIAlert 的 ok 时,它都会在这个委托(delegate)方法中返回;我该如何解决这个问题?我可以使用 BOOL 进行控制吗?

最佳答案

将第二个 alertView 的委托(delegate)设置为 nil。

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Danger" 
                                                    message:@"war"
                                                   delegate:nil 
                                          cancelButtonTitle:@"OK"
                                          otherButtonTitles:nil];

但是,如果您希望在将来为第二个添加选项,您可以为 alertView 设置一个 tag 值并检查调用的标签委托(delegate)方法。根据 tag 值,您将执行不同的任务。

关于objective-c - IOS:停止 UIAlert 循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6202148/

相关文章:

ios - 无法通过主类的选择器调用类别方法

objective-c - 为什么将框架 "install Directory"设置为 "@executable_path/../Frameworks"

ios - 如何在 xcode 8.2.1 中生成新的 ipa 文件?

ruby - 在 macOS App 中使用非系统 ruby​​ 执行 ruby​​ 脚本

c# - iOS 中带有 Xamarin.Forms 的 Autofac 4+ 无法构建

ios - 带有有序键的 NSDictionary

iOS 通用触摸处理程序

ios - 如何将数据从 UIContainerView 传递到位于同一父 View Controller 中的另一个 UIContainerView?

ios - 在容器 View Controller 中调整 View 大小

ios - 如何使用 Swift ios8 将网页的 url 通过 uiwebview 保存到表中