Switching to a TabBar tab view programmatically?

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

    My opinion is that selectedIndex or using objectAtIndex is not necessarily the best way to switch the tab. If you reorder your tabs, a hard coded index selection might mess with your former app behavior.

    If you have the object reference of the view controller you want to switch to, you can do:

    tabBarController.selectedViewController = myViewController
    

    Of course you must make sure, that myViewController really is in the list of tabBarController.viewControllers.

提交回复
热议问题