[英]Exception when presenting modal view controller: NSInternalInconsistencyException
当我尝试呈现模式视图控制器时,发生异常:
*** 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'
现在,我读了类似的问题,他们只是稍微延迟地打开了模态视图,例如
[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(openModalController) userInfo:nil repeats:NO];
演示文稿如下所示:
- (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:^{
}];
}
这不是真正的解决方案,对吗? 如何检查我的应用中某处是否正在进行过渡,并在当前过渡完成后立即打开新的模式视图?
这对我有用。 如果使用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.