iphone - 单击 alertView 的按钮后,不会调用 alertView didDismissWithButtomIndex

标签 iphone objective-c ipad ios

我最近开始研究 iOS 开发,如果我问的问题太明显,请原谅我。

当我的应用程序的 View 加载时,它会检查某些键的配置,如果这些键没有值,应用程序应显示警报并退出。

首先,我已经实现了 UIAlertViewDelegate:

@interface FirstViewController : UIViewController <UIAlertViewDelegate> {
...

然后检查设置:

    - (void)viewDidLoad {
          NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

              NSString *url = [defaults stringForKey:@"url"];
          NSString *apiKey = [defaults stringForKey:@"api-key"];

          if([url length] < 1 || [apiKey length] < 1){
           UIAlertView *dialog = [[[UIAlertView alloc] 
                       initWithTitle:@"Not properly configured" 
                       message:@"This application was not properly configured. Please configure the application on your iPhone settings." 
               delegate:self 
               cancelButtonTitle:@"Close"
               otherButtonTitles:nil]
               autorelease];
        [dialog setTag:1];
        [dialog show];
    }

    [url release];
    [apiKey release];
    [super viewDidLoad];
}

我知道 alertView didDismissWithButtomIndex 方法应该在 alertView 关闭后调用,但由于某种原因,我的代码中从未调用过此方法。

    - (void)alertView:(UIAlertView *)alertView                   didDismissWithButtomIndex:(NSInteger)buttomIndex {
               if([alertView tag] == 1){
                exit(0);
               }
}

关于为什么会发生这种情况的任何想法?

最佳答案

didDismissWithButtonIndex 拼写错误,您偷偷在其中添加了一个“m”而不是“n”。

关于iphone - 单击 alertView 的按钮后,不会调用 alertView didDismissWithButtomIndex,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4751492/

相关文章:

iphone - 将音频输出到配对的蓝牙设备?

iphone - 当我的设备自动锁定时获取通知

ios - 访问 cellforrow 之外的 tableview 内容

ios - 使用两个 NSSortDescriptor 来过滤数组

ipad - 为什么我无法在应用程序崩溃的情况下释放我的 CTFramesetter?

ios - UIPopoverController 显示的 UIViewController 的大小类错误

iphone - FlipView 关闭后如何刷新 View

iphone - Objective-C 中的模糊日期算法

iphone - 自动引用计数 (ARC) 中的 NSThreads

IOS 在 ScrollView 之间拖放