ios - iOS7 中的 UIAlertView 在关闭时锁定显示

标签 ios objective-c xcode ios7

在 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/

相关文章:

ios - 自定义后退按钮有额外的不需要的空间

ios - 将参数传递给 NSTimer 在 Swift 中调用的方法

ios - Swift:在没有 key 的情况下解析 JSON 字符串

objective-c - 桌面 Cocoa 中的 UIGraphicsGetImageFromCurrentImageContext 对应物?

objective-c - UIModalPresentationFullScreen 旋转问题

ios - 搜索栏取消按钮不重新加载原始 TableView 和数据

ios - 为什么每次加载新的 xib 文件时?为什么它不替换以前的文件?

ios - 从现有 NSArray 创建新 NSArray 的标准约定是什么?

iphone - NSXMLParser 从 XML 标签中检索错误数据

ios - 检查单击了哪个 UIAlertVeiw