How to "push" several View controllers onto the UINavigationController stack?

In my application, I implement a UINavigationController . There are several UIViewControllers that are UIViewControllers stack.

When I get to the last, I want (after user actions) all UIViewControllers to be pushed, except for the first UIViewController . How can I do it?

I understand how the last one comes up, but how do I indicate that all the previous ones disappear too?

+8
ios view release uinavigationcontroller pop
source share
3 answers

You can try the messages popToRootViewControllerAnimated: popToViewController:animated: and popViewControllerAnimated: of the UINavigationController class.

+22
source share

In your case, it is useful to use popToRootViewcontrollerAnimated: as suggested by Irene, but if someone needs a pop-up exact number of controllers, then the following code might be useful:

 - (void) popControllersNumber:(int)number { if (number <= 1) [[self navigationController] popViewControllerAnimated:YES]; else { NSArray* controller = [[self navigationController] viewControllers]; int requiredIndex = [controller count] - number - 1; if (requiredIndex < 0) requiredIndex = 0; UIViewController* requireController = [[[self navigationController] viewControllers] objectAtIndex:requiredIndex]; [[self navigationController] popToViewController:requireController animated:YES]; } } 
+9
source share

Using

  TravelViewController *travelView = [self.navigationController.viewControllers objectAtIndex:self.navigationController.viewControllers.count-3]; [self.navigationController popToViewController:travelView animated:YES]; 
+3
source share

All Articles