cocoa-touch - 无法让 UIAlert 工作

标签 cocoa-touch ios button uialertview exc-bad-access

有人发现这有什么问题吗?我有一个 UIAltertView,但当我单击两个按钮中的任何一个时,会收到 EXC_BAD_ACCESS:

    UIAlertView *alert = [[UIAlertView alloc] init];
    [alert setTitle:@"First Sync"];
    [alert setMessage:@"The App is going to do its first synchronisation. This might take a few moment..."];
    [alert setDelegate:self];
    [alert addButtonWithTitle:@"OK"];
    [alert addButtonWithTitle:@"Cancel"];
    [alert show];
    [alert release];

并捕获响应:

#pragma mark UIAlertView
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex != 0)
    {
            NSLog(@"TEST1");
        return;
    }   
NSLog(@"TEST2");
}

这一定是简单的事情......

最佳答案

您必须使用指定的初始值设定项:

initWithTitle:message:delegate:cancelButtonTitle:otherButtonTitles:

关于cocoa-touch - 无法让 UIAlert 工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4985821/

相关文章:

即使在更改后,iOS 应用程序仍显示旧应用程序图标

java - 当按下主页时,如何从开始的登录屏幕启动应用程序?

java - 为仪表板创建按钮,onClick 问题,也许更好的解决方案?

iphone - 如何在 iPhone 上记录 SQLite 查询

ios - iOS8 上的 Testflight 构建未安装

iphone - UIAppearance 代理缓存编译时间之间的外观?

iphone - 暂时使单元格可选择

javascript - slider 错误

ios - objective-c :没有@interface声明选择器错误

objective-c - 对象化妆,它是如何构建的?