开发者

How are people popping their UINavigationController stacks under a UITabBarController?

开发者 https://www.devze.com 2022-12-24 16:47 出处:网络
I have four UINavigationControllers assigned each to a tab in a UITabBarController. Each UINavigationController manages a UIViewController, which may itself branch out into other UIViewControllers bel

I have four UINavigationControllers assigned each to a tab in a UITabBarController. Each UINavigationController manages a UIViewController, which may itself branch out into other UIViewControllers below it hierarchally.

My question is, in a case in which a user, under one tab, has navigated to a UIViewController that hierarchally BELOW the main UIViewController m开发者_Python百科anaged by the UINavigationController, and then the user pushes a different tab, and then goes back to the original tab, HOW can I make it so that the user is presented with the main UIViewController managed by the UINavigation controller? and not the page where he left off?

UITabBarController is set up in IB


Implement the UITabBarControllerDelegate protocol and pop to the root controller whenever your delegate is notified that the user has selected a different tab.

Something like:

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
    [viewController.navigationController popToRootViewControllerAnimated:YES];
}

The code above should pop to the root controller of any navigation controller that is the main view controller of the newly selected tab. You could try implementing the protocol in your application delegate. And do not forget to actually assign the app delegate as the tab bar controller's delegate.


didn't work for me originally, then later on I noticed that all my viecontrollers for different tabs are actually UINavigationControllers

and thus I modified the above code a little bit as follows and it worked:

[(UINavigationController *)viewController popToRootViewControllerAnimated:NO];
0

精彩评论

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

关注公众号