Application tried to introduce modally active ios controller

I tried to set the ViewController with the parent view controller, before it shows that it can provide callbacks, I did this with PrepareForSegue

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

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

So I tried using a different method and set up a new controller on the button by pressing up,

 - (IBAction) buttonClicked { NewViewController *newController = [[NewViewController alloc] init]; [newController setParentViewController:self]; [self presentViewController:newController animated:YES completion:nil]; } 

but no luck, he still gives me the same error message, can anyone ask for advice? Thanks!

+4
ios objective-c segue modalviewcontroller viewcontroller
source share
4 answers

The issue has been resolved since the parent view controller is the tableViewController that was built into the navigationViewContoller. This is why segue should be pushed, not modalized.

+3
source share

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

Replace:

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

from:

 [self.navigationController pushViewController:newController animated:YES]; 
+2
source share

This line:

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

will execute MODAL segue, which gives an error.

Use this line instead:

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

executes a segue by “PUSHING” a new view controller onto the navigation controller stack (in Xcode 6 and later, this is the same as defining a segue type “show” on a storyboard). That is why you need it when you use the navigation controller.

+2
source share

Delete these 2 lines of code, no need to set the parent element, use delegation if you want feedback from NewViewController to the current self .

-one
source share

All Articles