Display multiple views from the navigation controller

I have an application in which its rootview is a menu of 4 table views that the user uses to configure a search query by selecting a cell that loads another view, so the main structure looks like this:

Root View - Parent View (search view) --Sub View (user selects variables here to fill search parameters of the parent view 

But one of the Parent View search options asks for another helper view that needs to be inserted into the navigation stack to look like

 Root View - Parent View (search view) --Sub View (user selects variables here to fill search parameters of the parent view ---Sub View (related values to the previous subview ie Model / sub model) 

I would like to know if there is a way to return to the Parent View from this additional view. I know that you can put one view or return to root mode, but in this case I want to pop two subheadings ... is this possible?

+4
source share
2 answers

UINavigationViewController

popToViewController: animated:

Controls view controllers until the specified view controller is at the top of the navigation stack.

 - (NSArray *)popToViewController:(UIViewController *)viewController animated:(BOOL)animated 
+11
source

You can add a category to the UINavigationController to display several controllers at once.

UINavigationController + VariablePop.h

 #import <UIKit/UIKit.h> @interface UINavigationController (VariablePop) - (NSArray *)popViewControllers:(int)numPops animated:(BOOL)animated; @end 

UINavigationController + VariablePop.m #import "UINavigationController + VariablePop.h"

 @implementation UINavigationController (VariablePop) - (NSArray *)popViewControllers:(int)numPops animated:(BOOL)animated { NSMutableArray* returnedControllers = [NSMutableArray array]; int indexToPopTo = self.viewControllers.count - numPops - 1; for(int i = indexToPopTo+1; i < self.viewControllers.count; i++) { UIViewController* controller = [self.viewControllers objectAtIndex:i]; [returnedControllers addObject:controller]; } UIViewController* controllerToPopTo = [self.viewControllers objectAtIndex:indexToPopTo]; [self popToViewController:controllerToPopTo animated:YES]; return returnedControllers; } @end 

And then from the view controller you can:

 NSArray* poppedControllers = [self.navigationController popViewControllers:2 animated:YES]; 
+2
source

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


All Articles