Application tried to present modally an active controller ios

user1494994 picture user1494994 · Nov 10, 2013 · Viewed 28.9k times · Source

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!

Answer

user1494994 picture user1494994 · Nov 10, 2013

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.