UITabBarController Set a Default Tab in Swift Language

别说谁变了你拦得住时间么 提交于 2019-12-11 09:47:17

问题


I have a UITabBarController that has 5 different view controllers attached to it. Each one has there own specific tab such as Home, Settings, etc. How can i set a certain tab to be the default tab when launched?


回答1:


Is there a specific reason why you can't move your chosen first tab to be presented to the left most slot?

self.tabBarController.selectedIndex = desiredIndex

or, if you're code is in a UITabBarConroller subclass, simply:

 selectedIndex = desiredIndex

should work.




回答2:


You could consider changing the tab in the app delegate's didFinishLaunchingWithOptions (or whatever owns the tab bar controller) with code like this:

if let tabController = window?.rootViewController as? UITabBarController {
        tabController.selectedIndex = 1
    }


来源:https://stackoverflow.com/questions/24785010/uitabbarcontroller-set-a-default-tab-in-swift-language

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