Switching to a TabBar tab view programmatically?

后端 未结 12 1947
南旧
南旧 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:40

    My issue is a little different, I need to switch from one childViewController in 1st tabBar to home viewController of 2nd tabBar. I simply use the solution provided in the upstairs:

    tabBarController.selectedIndex = 2
    

    However when it switched to the home page of 2nd tabBar, the content is invisible. And when I debug, viewDidAppear, viewWillAppear, viewDidLoad, none of them is called. My solutions is to add the following code in the UITabBarController:

    override var shouldAutomaticallyForwardAppearanceMethods: Bool 
    {
        return true
    }
    

提交回复
热议问题