我有一个UITabBarController我正在为它的ViewControllers列表设置一些ViewControllers,如下图
let tabBar = UITabBarController();
tabBar.viewControllers = vcs;
加载视图时,将显示vcs
列表中的第一个ViewController。我想要的是,显示一个UIViewController不是在vcs
列表(和没有选项栏必须被选中)。我想只在视图第一次加载时才显示这个UIViewController。在用户点击其中一个tabBarItems之后,我想要加载关联的ViewController。所以我的问题是"显示一个UIViewController"不在vcs
列表
看UITabBarControllerDelegate
方法tabBarController(_:shouldSelect:)
。
让你自己委托你的UITabBarController
,这取决于你是否使用Storyboard,它可能更容易创建一个自定义类继承自UITabBarController
本身是delegate
,并将该类设置为Storyboard。
var hasNotShownYet = false
func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
guard hasNotShownYet else { return true /* Allow selection as "normal" */ }
presentCustomVCModally()
hasNotShowYet = true
return false
}