5

我遇到了崩溃:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIKeyboardTaskQueue performTask:] may only be called from the main thread.'

我找不到解决方案 2 天。这是代码:

[alert dismissWithClickedButtonIndex:0 animated:YES];
UIAlertView *noTicketAlert = [[UIAlertView alloc] initWithTitle:@"Aradığınız kriterlere uygun bilet bulunamadı!" message:nil delegate:self cancelButtonTitle:@"Tamam" otherButtonTitles: nil];
[noTicketAlert show];
4

5 回答 5

10

我通过尝试显示来自后台线程的警报触发了此错误。像这样固定:

dispatch_async(dispatch_get_main_queue(), ^{
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:...
    [alertView show];
});
于 2014-03-31T22:16:39.070 回答
8

正常呈现 UIAlertView 时出现此错误(没有有趣的按钮覆盖内容)。事实证明,我连续两次展示了它。在我的情况下,解决方法是删除错误的重复调用。

如果您确实需要同时显示两个警报视图,并且您收到此错误,那么有效的修复(并解决错误消息本身)是在主线程上运行代码:

[[NSOperationQueue mainQueue] addOperationWithBlock:^
    {
    // Your code that presents the alert view(s)
    }];
于 2013-10-10T23:48:08.453 回答
1

是的,我找到了解决方案,并与大家分享。我试图覆盖该函数,并为我的每个警报dismissWithClickedButtonIndex发送唯一的按钮索引。9999那是,

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex {
    [self viewWillDisappear:YES];
    if(buttonIndex == 9999) {
        noTicketAlert = [[UIAlertView alloc] initWithTitle:@"Aradığınız kriterlere uygun bilet bulunamadı!" message:nil delegate:self cancelButtonTitle:@"Tamam" otherButtonTitles: nil];
        [noTicketAlert show];
    }
}

如果我想显示noticketAlert,我调用这个方法:

[alert dismissWithClickedButtonIndex:9999 animated:YES];
于 2013-09-25T15:01:33.587 回答
0

如果您有自定义按钮,请确保您实现了委托方法:

- (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView
{
    return YES;
}

如果找不到此选择器,则程序崩溃..

于 2013-10-07T01:19:36.607 回答
0

对于那些寻找这个问题的 Swift 2 答案的人,我遇到了一个类似的问题,并用 @Dave Batton 的解决方案解决了它

dispatch_async(dispatch_get_main_queue(), {
    self.performSegueWithIdentifier("loginSegue", sender: self)
})
于 2016-03-01T18:42:00.900 回答