Switching to a TabBar tab view programmatically?

后端 未结 12 1937
南旧
南旧 2020-11-29 17:07

Let\'s say I have a UIButton in one tab view in my iPhone app, and I want to have it open a different tab in the tab bar of the TabBarController.

12条回答
  •  情歌与酒
    2020-11-29 17:32

    import UIKit
    
    class TabbarViewController: UITabBarController,UITabBarControllerDelegate {
    
    //MARK:- View Life Cycle
    
    override func viewDidLoad() {
        super.viewDidLoad()
    
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    
    }
    
    //Tabbar delegate method
    override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
        let yourView = self.viewControllers![self.selectedIndex] as! UINavigationController
        yourView.popToRootViewController(animated:false)
    }
    
    
    
    }
    

提交回复
热议问题