0

当我尝试呈现模态视图控制器时,会发生异常:

*** 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:^{

}];
}

这不可能是真正的解决方案,对吗?我如何检查我的应用程序中是否正在进行某些转换,并在当前转换完成后立即打开新的模态视图?

4

1 回答 1

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];
    }
}
于 2013-11-27T14:22:03.470 回答