ios - 有条件地在 UITabBar 选择上显示 View Controller

标签 ios objective-c swift uitabbarcontroller

上下文:当点击我的“用户”选项卡栏项目时,我想检查用户是否已登录。如果是,我想显示我的“个人资料” 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/

相关文章:

ios - 画三角形 iOS

objective-c - GKachievement(游戏中心)正在显示?

ios - 在 xcode 上使用 sprite kit 创建黑洞

swift - 从 SF Symbols 字体创建一个不同颜色的 SKSpriteNode

swift - 在 UITabBarController 中从 VC 转出后导航栏丢失

ios - 使用类别中的 block 扩展 UIRefreshControl

ios - UIImagePickerController 作为应用程序的主视图 Controller 和随后显示的导航 Controller

ios - iOS 中的触摸点

iphone - 我如何在cocos2d中使用动画?

ios - Swift 将 sizeof 与 Int32 数组一起使用