IPhone - parental modal view rejection

I am drawing an application workflow where you have the main menu “Level 0”, which brings up the modal view “Level 1”, which calls up the other modal view “Level 0”.

I can get this job, no problem. And I can reject the entire stack using:

[[[self parentViewController] parentViewController] dismissModalViewControllerAnimated:YES]; 

in the modal view "Level 2".

My problem is that there is a navigation bar in the Level 2 modal view. I can’t remove the whole stack. The code above returns me only one level, so it acts just as if I did this:

 [self dismissModalViewControllerAnimated:YES]; 

in the modal view "Level 2".

Summary: When a Level 1 modal view calls up a Level 2 modal view, use the following:

 Level2 *level2 = [[[Level2 alloc] initWithNibName:@"Level2" bundle:nil] autorelease]; [self presentModalViewController:portalMainController animated:YES]; 

I can delete the entire stack and return to the main menu (Level 0). BUT, when "Level 1" calls up "Level 2" with the navigation bar, as shown below:

  Level2 *level2 = [[[Level2 alloc] initWithNibName:@"Level2" bundle:nil] autorelease]; UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:level2]; [self presentModalViewController:navigationController animated:YES]; [navigationController release]; 

I can’t go back to Level 0, I’ll only go back to Level 1.

Any suggestions?

+4
source share
2 answers

I would create a protocol for a level 2 controller such as Level2Delegate. Then set the level 2 controller delegate as level 1 controller. Then you can do something like the following:

A level 2 controller will implement this when self.delegate is a level 1 controller

 [self.delegate controllerDidFinish:self]; 

Level 1 will be implemented:

 - (void)controllerDidFinish:(Level2Controller *)controller { [[self parentViewController] dismissModalViewControllerAnimated:NO]; } 

The key is to set up a chain of events, rather than trying to fire both at once.

+2
source

Why not use

 [self.navigationController popToRootViewControllerAnimated:YES]; 
0
source

Source: https://habr.com/ru/post/1315346/


All Articles