开发者

Changing viewcontroller for a tab in a tabbar controller

I am currently developing an app that has a TabBarController and each of the tabs contains a navigation controller. This way on each tab I can show details of the rows s开发者_开发问答elected on a view by pushing the viewcontroller to the navigation controller. Each of the views also have an UINavigationItem above them. In this navigation item I placed a button.

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

So I do not want to push another view on the navigation controller, but just switch to that view (in the same tab) and have that act as the root view controller.

I cannot find a good way to do this, with actually having the views work correctly. They either do not dealloc when I switch views (which would be nice, because I want to keep memory usage to a minimum).

One way of solving this, might be that I add more tabs to my TabBar Controller and just switch to the right tabs when I click the button, but that would be a last resort.

Not really sure if I described this correctly, but I was wondering what the best way is to do this. My preference is having 3 viewcontrollers and switch between them.


Hopefully I understand your question correctly: you want to basically 'reset' your navigation controller to have a new root.

You can do this by telling your 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 on that navigation controller's stack, and reset the root view to newViewController.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜