无法让UIAlert工作

时间:2011-02-13 17:55:19

标签: 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");
}

一定是简单的......

2 个答案:

答案 0 :(得分:1)

您必须使用指定的初始化程序:

initWithTitle:message:delegate:cancelButtonTitle:otherButtonTitles:

答案 1 :(得分:0)

如上所述,问题在于UIAlert是在线程中生成的。通过使用NSCondition并将Alert发送到后台线程,我让工作线程等待后台线程等待用户的响应。一旦响应到来,它就会通知工作线程继续(因为此时所需的数据存储在数据库中)。

相关问题