简体   繁体   English

呈现模式视图控制器时的异常:NSInternalInconsistencyException

[英]Exception when presenting modal view controller: NSInternalInconsistencyException

when I try to present a modal view controller, an exception occurs: 当我尝试呈现模式视图控制器时,发生异常:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', 
reason: 'Attempting to begin a modal transition from <UINavigationController: 0x1d906060>
to <UINavigationController: 0x1da7a6d0> while a transition is already in progress. Wait
for viewDidAppear/viewDidDisappear to know the current transition has completed'

Now, I read similar questions, where they simply opened the modal view with a tiny delay, like 现在,我读了类似的问题,他们只是稍微延迟地打开了模态视图,例如

[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(openModalController) userInfo:nil repeats:NO];

The presentation looks like this: 演示文稿如下所示:

- (void)openImage:(ImageModel *)imageModel{
FullscreenImageViewController_iPhone * controller = [[FullscreenImageViewController_iPhone alloc] init];
controller.imageModel = imageModel;
UINavigationController * navController = [[UINavigationController alloc] initWithRootViewController:controller];
UIViewController * visibleController = [[AppDelegate_iPhone app] visibleViewController];
[visibleController presentViewController:navController animated:YES completion:^{

}];
}

This can´t be the real solution, can it? 这不是真正的解决方案,对吗? How can I check, if some transition is going on somewhere in my app and the open the new modal view right after the current transition has finished? 如何检查我的应用中某处是否正在进行过渡,并在当前过渡完成后立即打开新的模式视图?

This works for me. 这对我有用。 If you use the isBeingPresented and isBeingDismissed methods of UIViewController to test whether a presentation or dismissal is ongoing, wait a while and try again: 如果使用UIViewController的isBeingPresented和isBeingDismissed方法测试演示或解雇是否正在进行,请稍等片刻,然后重试:

- (void) presentVC {    
    if (presentingVC.isBeingPresented || presentingVC.isBeingDismissed) {
         double delayInSeconds = 0.3;
         dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
         dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
               [self presentVC];
         });
    }
    else {
        [presentingVC presentViewController:presentedVC animated:NO completion:nil];
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM