当我尝试呈现模态视图控制器时,会发生异常:
*** 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:^{
}];
}
这不是真正的解决方案,可以吗?我如何检查,如果我的应用程序中某处发生了某些转换,并且在当前转换完成后立即打开新的模式视图?
答案 0 :(得分:0)
这对我有用。如果您使用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];
}
}