为什么UIAlertView没有显示?

Rui*_*Rui 4 iphone objective-c ios-simulator

由于某种原因,屏幕变暗并冻结,警报未显示...有人可以帮忙吗?

提前致谢!

} else {
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Hello!" 
                                                message:@"Hello!" delegate:self 
                                      cancelButtonTitle:@"Done" 
                                      otherButtonTitles:nil];
    [alert show];
    [alert release];
}
Run Code Online (Sandbox Code Playgroud)

Lac*_*che 15

您可能正在show从后台线程调用,在主线程上调用它,如下所示:

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Hello!" 
                                            message:@"Hello!" delegate:self 
                                            cancelButtonTitle:@"Done" 
                                            otherButtonTitles:nil];
[alert performSelectorOnMainThread:@selector(show)
                            withObject:nil
                            waitUntilDone:NO];
[alert release];
Run Code Online (Sandbox Code Playgroud)