上下文:当点击我的“用户”选项卡栏项目时,我想检查用户是否已登录。如果是,我想显示我的“个人资料” View ,如果没有,我想显示我的“日志”在” View 中。我应该怎么做呢?我已经尝试子类化 UITabBarController
并将我的逻辑放在 prepareForSegue
函数中,但无济于事。
本质上,我如何选择在选择标签栏项时要推送的 View Controller ?
最佳答案
你要的是UITabBarControllerDelegate
的委托(delegate)方法
optional func tabBarController(_ tabBarController: UITabBarController,
shouldSelectViewController viewController: UIViewController) -> Bool
文档
Return Value
YES if the view controller’s tab should be selected or NO if the current tab should remain active.
Discussion
The tab bar controller calls this method in response to the user tapping a tab bar item. You can use this method to dynamically decide whether a given tab should be made the active tab.
关于ios - 有条件地在 UITabBar 选择上显示 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31420899/