开发者

Switching from one tab to another in a application

开发者 https://www.devze.com 2023-04-06 18:14 出处:网络
I have two tabs in the application. From tab 2 on a particular view i want to switch to Root View of the 1st tab.

I have two tabs in the application. From tab 2 on a particular view i want to switch to Root View of the 1st tab. how do i do this?

In this case simply self.tabBarController.selectedIndex = 0; wont work as it does not shows root view it shows the view to which user has navigated to before le开发者_运维百科aving that tab.

I wish to directly switch to first view of the tab 1


I'm guessing that tab1 is a UINavigationController. You will need to popToRootViewController on the first tab

- (NSArray *)popToRootViewControllerAnimated:(BOOL)animated

Depending on how your application is configured, you might create a method on your appdelegate or somewhere in your view hierarchy that hosts both the UITabBarController and the UINavigationController.

If you always want to display the first view of a particular tab when the user returns to it, call the popToRootView from a viewDidDissapear method somewhere. There are lots of ways to do it, but think about the user experience if you do it automatically.

0

精彩评论

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

关注公众号