Reputation:
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!
Upvotes: 5
Views: 30412
Reputation:
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.
Upvotes: 4
Reputation: 32010
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.
Upvotes: 2
Reputation: 2576
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];
Upvotes: 3