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 を通常どおりに表示すると、このエラーが発生しました (面白いボタンのオーバーライドはありません)。立て続けに 2 回提示していたことが判明しました。私の場合の修正は、誤った重複呼び出しを削除することでした。

ほぼ同時に 2 つのアラート ビューを表示する必要があり、このエラーが発生した場合、機能する (そしてエラー メッセージ自体に対処する) 修正は、メイン スレッドでコードを実行することです。

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

この問題に対するSwift 2の回答を探している人のために、私は同様の問題に遭遇し、@ Dave Battonのソリューションで解決しました

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