我有一个关于iOS7上的UIAlertView的问题。当我启动我的应用程序时,它崩溃了,并显示以下消息:
*** Assertion failure in -[UIKeyboardTaskQueue performTask:], /SourceCache/UIKit_Sim/UIKit-2903.2/Keyboard/UIKeyboardTaskQueue.m:388错误发生在以下行:
- (IBAction)updatePositions:(id)sender{
_alert = [[UIAlertView alloc] initWithTitle:@"text" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
[_alert show]; <====== IT CRASHS HERE
[NSThread detachNewThreadSelector:@selector(updateDataThread) toTarget:self withObject:nil];
}我使用的是ARC,属性_alert被设置为:@property (nonatomic,strong)
这个错误看起来很奇怪,因为在iOS6上代码运行得很好,我不知道在iOS7上应该有什么不同。
有没有人知道这个错误是什么?
提前谢谢。
发布于 2013-11-03 11:22:25
我遇到了同样的错误,问题是UIAlertView试图从不是主线程的线程中显示。
然而,崩溃并不总是发生,只有当第一个AlertView已经显示,而第二个AlertView也试图弹出时才会发生。
在我的例子中,一个简单的修复方法是:
//Your code here
...
//Alert
_alert = [[UIAlertView alloc] initWithTitle:@"text" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
dispatch_async(dispatch_get_main_queue(), ^{
//Show alert here
[_alert show];
});
//Resume your code here
...发布于 2013-10-05 09:28:44
我只是忘记了我是在后台线程中工作,所以才有了这个问题。我不知道这里是不是这样,但我要确保您不会尝试从主线程以外的任何地方调用updatePositions。
发布于 2013-10-03 23:01:35
像这样修改你的代码:
_alert = [[UIAlertView alloc] initWithTitle:@"text" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
[_alert show];删除@"text“周围的[ and ]
但是,你的我不认为你的问题来自于这个UIAlertView。
https://stackoverflow.com/questions/19162508
复制相似问题