Question

In a project I'm writing I get this error when I present a new view controller:

Attempt to present.... while a presentation is in progress!

I think it happens because I first present a new view controller, and then in that view I present another view controller.

- (void)loadLabelSettings {
    LabelSettingsViewController *labelSettings = 
      [[LabelSettingsViewController alloc] init];
    labelSettings.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self presentViewController:labelSettings animated:YES completion:nil];
}

The program doesn't crash or anything it runs just fine, and there is no errors or warnings in my code. So my question is: Is it something I should be concerned with and if yes how do I solve it?

Thanks in advance :)

Was it helpful?

Solution

It is, like you said, probably caused by presenting two view controllers at the same time. Wait with presenting the second view controller until the first one has been fully presented. A good location would be to do this in viewDidAppear.

OTHER TIPS

In my case, I connected a UIViewControllers UIButton with a second UIViewController by a UIStoryboardSegue. Inside my code a called it a second time programmatically. So pressing the UIButton caused presenting the specified view two times.

I figured out my problem, as Scott wrote it was because I was presenting 2 view controllers at the same time. It happened because I had a button that had a UILongPressGestureRecognizer, that showed the new view controller. The problem was that when using a UILongPressGestureRecognizer, the method that is being called, is called twice. First when the long press is detected and when your finger is released from the screen. So the presentViewController method of the same view, was called twice. I fixed this by only reacting to the first detection. Here is the code :

- (void)loadButtonSettings:(UILongPressGestureRecognizer *)recognizer {

   if (recognizer.state == UIGestureRecognizerStateBegan) {

   }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top