How are people popping their UINavigationController stacks under a UITabBarController?

让人想犯罪 __ 提交于 2019-12-07 02:50:28

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];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!