简体   繁体   中英

How to pop to root view controller on UITabBarItem switch?

我有一个带有两个UINavigationControllerUITabBarController ,当我从一个TabBarItem切换到另一个时,先前选择的视图控制器应弹出到其根视图控制器。

Implement the UITabBarControllerDelegate tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) method like this:

func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
   if let navigationController = viewController as? UINavigationController{
       navigationController.popToRootViewController(animated: false)
   }
   return true
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM