3

Crashlytics から、アプリで次のエラーが送信されます。

Fatal Exception: NSInternalInconsistencyException
Trying to dismiss UIAlertController <UIAlertController: 0x14de40020> with unknown presenter.

UIKit   
-[UIAlertController _dismissAnimated:triggeringAction:triggeredByPopoverDimmingView:] + 584

この問題は iOS 8 でのみ発生しますが、このエラーを再現しようとするとalertViews、iOS 8 で正しく動作し、悪いことは何も起こりません。なぜこの問題が起こっているのですか?

iOS 8UIAlertViewでは非推奨になっていることを読みましたが、今は使用する必要がありますUIAlertControllerが、UIAlertController を使用しようとすると、アラートを閉じることができず、機能も同じではありません。

私を助けてください。

よろしくお願いします。

編集:

変更したいコードは次のとおりです。

UIAlertView * alerta = [[UIAlertView alloc] initWithTitle: AMLocalizedString(@"alertUpdate", @"")
                                                  message:@"\n"
                                                 delegate:self
                                        cancelButtonTitle:nil
                                        otherButtonTitles:nil];

UIActivityIndicatorView *spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
spinner.center = CGPointMake(139.5, 75.5); // .5 so it doesn't blur
[alerta addSubview:spinner];
[spinner startAnimating];
[alerta show];


UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:dis bundle:nil];
MainVC *main = [storyBoard instantiateViewControllerWithIdentifier:@"MainVC"];
UINavigationController *navControl = [[UINavigationController alloc] initWithRootViewController: main];
[self presentModalViewController: navControl animated: YES];

[alerta dismissWithClickedButtonIndex:0 animated:YES];
4

3 に答える 3

3

これを交換

[self presentModalViewController: navControl animated: YES];
[alerta dismissWithClickedButtonIndex:0 animated:YES];

これとともに

[alerta dismissWithClickedButtonIndex:0 animated:YES];
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
    [self presentModalViewController: navControl animated: YES];
}]; 

これにより、新しいコントローラーが非同期的に表示され、アラート ビューが確実に閉じられます。

于 2015-03-30T09:46:39.637 に答える
1

これを解決できたかどうかはわかりませんが、同様の問題があり、ここに潜在的な解決策があります。

UIAlertViewDelegate プロトコルを実装し、 alertView:didDismissWithButtonIndex:メソッドをオーバーライドします 。

ビュー コントローラーの表示または非表示は、このメソッドで発生し、別の場所に移動して "プレゼンター" が不明になる前に AlertView が完全に非表示になることを 100% 確実にする必要があります。

これは、UIActionSheet ボタンのクリックから移動するときにも実行できます。

于 2014-11-11T20:10:25.273 に答える
0

popoverPresentationControllerに設定UIAlertController

このコードのように使用します:

UIAlertController * alertController = [UIAlertController alertControllerWithTitle:@"Title"
                                                                                  message: nil
                                                                           preferredStyle: UIAlertControllerStyleActionSheet];
        [alertController addAction: [UIAlertAction actionWithTitle: @"title" style: UIAlertActionStyleDefault handler:^(UIAlertAction *action) {

        }]];
CGRect rect = self.view.frame;
 rect.origin.x = self.view.frame.size.width / 20;
 rect.origin.y = self.view.frame.size.height / 20;
[alertController.popoverPresentationController setPermittedArrowDirections:0];
alertController.popoverPresentationController.sourceView = self.view;
alertController.popoverPresentationController.sourceRect = rect;
[alertController setModalPresentationStyle:UIModalPresentationPopover];
[self presentViewController: alertController animated: YES completion: nil];
于 2014-10-30T09:40:14.660 に答える