0

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?

stk
  • 6,311
  • 11
  • 42
  • 58
  • It would be helpful if you'd show your transition code. – Mick MacCallum Dec 11 '12 at 16:36
  • I've seen this error occur when you try to present a modal from the viewDidLoad method. Is that what you're doing? If so, you can move the presentation code to viewDidAppear. – rdelmar Dec 11 '12 at 16:36
  • No, it´s triggered during 'idle runtime'. A user clicks on something, then something fullscreen is opened. – stk Dec 11 '12 at 16:40
  • You are either trying to present one modal view controller while another is being dismissed (the animations overlap) or maybe you are somehow presenting the new one twice at essentially the same time. – rmaddy Dec 11 '12 at 16:43
  • Thanks rmaddy, I think this was clear already. I´m looking for something like a queue, that displays transitions one after another or for something like a static method of UIView, which could tell me if a transition is already going on. Anybody heard of things like that? – stk Dec 20 '12 at 15:45

1 Answers1

0

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:

- (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];
    }
}
Mikkel Selsøe
  • 1,171
  • 1
  • 11
  • 23
  • As you probably can see from my code fragment, problem is that there are 2 ViewControllers. So there´s one VC that´s currently dismissing something and at the same time the VC that I want to open. So with your approach you have to have an instance of both VCs, which I don´t have in most of my code. – stk Dec 02 '13 at 14:10
  • OK. You could keep the VC being presented around in an instance variable until it has been presented (that is until the completion block is called). – Mikkel Selsøe Dec 03 '13 at 09:31