swift - 根据值设置 TabBarController 索引的 View Controller

标签 swift firebase-realtime-database uinavigationcontroller uitabbarcontroller

我的 Firebase 数据库中有一个特定于用户的值。
简化为a或b。我在我的应用程序中使用 TabBarController:
如果值为 a,则索引 0 的 ViewController(嵌入在导航 Controller 中)应与值为 b 时不同。
选项卡栏 -> 导航 Controller (索引 0) -> ViewController A 或 B

我可以以某种方式在 TabBarController 类、导航 Controller 类中设置它还是应该如何进行?

最佳答案

没有像您想象的那样的直接配置,但是如果您在显示 tabBar 之前获取值,您可以在它的自定义类中执行此操作

class CustomTab:UITabBarController {

   override func awakeFromNib() {
     super.awakeFromNib()

    let nav = self.viewControllers[0] as! UINavigationController

     if a {
       let vcA = ///
       nav.viewControllers = [vcA]
      }
     else {
       let vcB = ///
       nav.viewControllers = [vcB]
     }
  }
}

关于swift - 根据值设置 TabBarController 索引的 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52456464/

相关文章:

ios - 每次按下按钮时如何使 scrollView 移动?

java - 如何读取不变的数据?

swift - 尝试从 Firebase 检索数据时遇到问题

ios - performSegue 将下一个 View Controller 插入不需要的 View 层次结构

swift - 在不创建新实例的情况下调用其他 View Controller

swift - MIME 类型的所有应用程序 URL

iphone - 当用户点击 UINavigationController 后退按钮时执行某些操作

ios - 向后滑动时 UINavigationController 白线故障

ios - 如何从存储在 iOS 钥匙串(keychain)中的 key 获取 DER 格式的公钥?

javascript - 使用fb身份验证的firebase json db安全规则