Application tried to present modally an active controller ios
Asked Answered
I

3

5

I was trying to set the ViewController with a parent view controller before it shows show that it can provide call backs, I done this using PrepareForSegue

- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"newQuarter"])
    {
        [segue.destinationViewController setParentViewController:self];
    }
}

It crashed giving me the error message: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present modally an active controller.

So I tried using another method and set up a new view controller on the button touches up,

- (IBAction) buttonClicked
{
    NewViewController *newController = [[NewViewController alloc] init];
    [newController setParentViewController:self];

    [self presentViewController:newController animated:YES completion:nil];
}

but with no luck it is still giving me the same error message, can anyone please advice? Thanks!

Intermigration answered 10/11, 2013 at 20:52 Comment(2)
possible duplicate of "Application tried to present modally an active controller"?Elf
@CarlVeazey this is not a duplicate of "Application tried to present modally an active controller". Thank you for suggesting though! :DIntermigration
I
4

Resolved the problem, since the parent view controller is a tableViewController, which it was embedded in a navigationViewController. That's why the segue should be pushed rather then performing modal transition.

Intermigration answered 10/11, 2013 at 22:24 Comment(0)
F
3

I had the same issue and Matthew's explanation seems correct.

Replace:

[self presentViewController:newController animated:YES completion:nil];

with:

[self.navigationController pushViewController:newController animated:YES];
Finbar answered 28/10, 2014 at 15:26 Comment(0)
S
2

This line:

[self presentViewController:newController animated:YES completion:nil];

will perform a MODAL segue, which is what gives the error.

Using this line instead:

[self.navigationController pushViewController:newController animated:YES];

performs a segue by 'PUSHING' a new view controller onto the Navigation Controller stack (in XCode 6 and above, this is the same thing as defining a segue type of 'show' on the storyboard). This is why you need this when you're using a Navigation Controller.

Stern answered 12/10, 2015 at 5:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.