这是我的代码:
UIAlertView *someError = [[UIAlertView alloc] initWithTitle:nil message:@"Server Error!" delegate:nil cancelButtonTitle: @"ok" otherButtonTitles: nil];
[someError show];
当我点击确定按钮时,警报背景仍然存在,我点击屏幕时,状态栏正在闪烁。
我找到了一些答案,但它们不起作用,我将代码更改为:
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertView *someError = [[UIAlertView alloc] initWithTitle:nil message:@"Server Error!" delegate:nil cancelButtonTitle: @"ok" otherButtonTitles: nil];
[someError show];
});
或设置委托:
dispatch_async(dispatch_get_main_queue(), ^{
UIAlertView *someError = [[UIAlertView alloc] initWithTitle:nil message:@"Server Error!" delegate:self cancelButtonTitle: @"ok" otherButtonTitles: nil];
[someError show];
});
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
dispatch_async(dispatch_get_main_queue(), ^{
[alertView dismissWithClickedButtonIndex:buttonIndex animated:NO];
});
}
它仍然不起作用,然后我尝试:
UIAlertView *someError = [[UIAlertView alloc] initWithTitle:nil message:@"error" delegate:nil cancelButtonTitle: @"ok" otherButtonTitles: nil];
[someError performSelectorOnMainThread:@selector(show) withObject:nil waitUntilDone:NO];
不行,疯了,这也不行:
[self performSelectorOnMainThread:@selector(showAlert:) withObject:@"error", nil) waitUntilDone:NO];
// the show Alert function
-(void)showAlert:(NSString*)str
{
UIAlertView *someError = [[UIAlertView alloc] initWithTitle:nil message: str delegate: nil cancelButtonTitle: @"ok" otherButtonTitles: nil];
[someError performSelectorOnMainThread:@selector(show) withObject:nil waitUntilDone:NO];
}
还是不行。
警报显示前后: