显示不在 UITabBarController 的 viewControllers 列表中的 ViewController
Show a ViewController that is not in UITabBarController's viewControllers list
我有一个 UITabBarController,我正在为它的 viewControllers 列表设置一些 ViewController,如下所示
let tabBar = UITabBarController();
tabBar.viewControllers = vcs;
加载视图时,将显示 vcs
列表中的第一个 ViewController。
我想要的是,显示不在 vcs
列表中的 UIViewController(必须选择 tabBar 的 none)。
我只想在第一次加载视图时显示此 UIViewController。在用户点击其中一个 tabBarItems 之后,我想加载关联的 ViewController。
所以我的问题是 'Showing a UIViewController' 不在 vcs
列表
中
查看UITabBarControllerDelegate
方法tabBarController(_:shouldSelect:)
。
让自己成为 UITabBarController
的代表,这取决于您是否使用 Storyboard,创建一个继承自 UITabBarController
的自定义 class 可能更容易 [=15] =] 并将 class 设置到情节提要中。
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
}
我有一个 UITabBarController,我正在为它的 viewControllers 列表设置一些 ViewController,如下所示
let tabBar = UITabBarController();
tabBar.viewControllers = vcs;
加载视图时,将显示 vcs
列表中的第一个 ViewController。
我想要的是,显示不在 vcs
列表中的 UIViewController(必须选择 tabBar 的 none)。
我只想在第一次加载视图时显示此 UIViewController。在用户点击其中一个 tabBarItems 之后,我想加载关联的 ViewController。
所以我的问题是 'Showing a UIViewController' 不在 vcs
列表
查看UITabBarControllerDelegate
方法tabBarController(_:shouldSelect:)
。
让自己成为 UITabBarController
的代表,这取决于您是否使用 Storyboard,创建一个继承自 UITabBarController
的自定义 class 可能更容易 [=15] =] 并将 class 设置到情节提要中。
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
}