在 iOS7 发布之前,我在 iOS 版本中使用以下代码没有问题,现在当我尝试在 iOS7 上运行它时,我得到了不想要的结果。
[self.view setUserInteractionEnabled:YES];
mAlert=[[UIAlertView alloc] initWithTitle:@"Alert" message:@"There are no more reports matching this search query." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[mAlert show];
[SVProgressHUD dismiss];
将出现警告消息并提示用户点击“确定”。当警报消失时,我现在只剩下一个无法再与之交互的 View ,唯一的解决方案是重新运行该应用程序。该应用程序本身并没有像我对其进行配置时那样“卡住”,并且可以看到它仍然存在,我只是无法与之交互。我实现了 UIAlertViewDelegate,下面是我对 didDismissWithButtonIndex: 函数的实现
-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex: (NSInteger)buttonIndex {
mAlert = nil;
}
我已经尝试了很多东西,但仍然一无所获。令人难以置信的沮丧,我觉得我错过了一些微不足道的东西。
最佳答案
您确定该方法正在主线程中运行吗?任何对 UI 执行某些操作的方法都需要在主线程上运行,而不是在后台线程上运行。
如果你想显示来自后台线程的警告,在你的后台方法中试试这个:
[self performSelectorOnMainThread:@selector(showAlert) withObject:nil waitUntilDone:YES];
然后添加这样的方法
- (void) showAlert {
UIAlertView *mAlert=[[UIAlertView alloc] initWithTitle:@"Alert" message:@"There are no more reports matching this search query." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[mAlert show];
}
关于ios - iOS7 中的 UIAlertView 在关闭时锁定显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19411817/