在swift中设置UITabBar中的默认选项卡 [英] Setting default tab in UITabBar in swift

查看:600
本文介绍了在swift中设置UITabBar中的默认选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我差不多完成了一个项目,并且正在研究最后几个UI扭结。我的应用程序使用标签栏进行导航,出于审美目的,我希望应用程序在最后一个选项卡(用户配置文件)而不是第一个选项卡上打开。我知道我可以重新排序Interface Builder中的选项卡,但是标签栏看起来很奇怪,首先是配置文件选项卡,其他地方是主页选项卡。如何将配置文件选项卡保留为第5个选项卡,但默认情况下在该选项卡上打开应用程序?

I'm almost finished with a project and am working out the last few UI kinks. My app uses a tab bar to navigate and for aesthetic purposes I want the app to open on the last tab (User Profile) instead of the first. I know I can reorder the tabs in Interface Builder but the tab bar would just look odd having the profile tab first and the home tab anywhere else. How can I leave the profile tab as the 5th tab yet by default open the app on that tab?

推荐答案

只需设置selectedIndex tabBarController的内容。沿着这些方向的东西。

Just set the selectedIndex of the tabBarController. Something along these lines.

var freshLaunch = true
override func viewWillAppear(animated: Bool) {
     if freshLaunch == true {
         freshLaunch = false
         self.tabBarController.selectedIndex = 4 // 5th tab
     }
}

这篇关于在swift中设置UITabBar中的默认选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆