Changing the view manager for a tab in a tab controller

I am currently developing an application with TabBarController, and each of the tabs contains a navigation controller. Thus, on each tab, I can show the details of the rows selected in the view by clicking on the view controller on the navigation controller. Each view also has a UINavigationItem above them. In this navigation element, I placed a button.

But now I would like to change the viewcontroller for a specific tab when I click a button in the UINavigationItem, BUT the view (controller) that I want to change should act as the root view controller of that tab.

Therefore, I don’t want to click another view on the navigation controller, but just switch to this view (on the same tab) and act as the root view controller.

I cannot find a good way to do this, actually having the views correctly. Either they are not released when switching views (which would be nice, because I would like to minimize memory usage).

One way to solve this problem may be that I add additional tabs to my TabBar controller and just switch to the desired tabs when I click the button, but that would be the last resort.

Not quite sure if I described it correctly, but I was wondering how best to do it. My preference is that I have 3 view controllers and switch between them.

+4
source share
1 answer

I hope I understood your question correctly: you basically want to β€œreset” your navigation controller to have a new root.

You can do this by telling the navigation controller that you want to display a new set of view controllers:

[navigationController setViewControllers:[NSArray arrayWithObject:newViewController] animated:NO]; 

This will get rid of all view controllers currently in this navigation controller stack and reset the root view of newViewController .

+7
source

All Articles