【问题标题】:programmatically set initial view controller to tab controller swift 2以编程方式将初始视图控制器设置为选项卡控制器 swift 2
【发布时间】:2016-07-12 15:22:25
【问题描述】:

我的 iOS 应用上有一个选项卡控制器,我想先检查一些条件并执行以下操作:

self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
let mainStoryBoard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
if condition {
        globalClass.token = u
        let mvc: MainViewController = mainStoryBoard.instantiateViewControllerWithIdentifier("mainView") as! MainViewController
        self.window?.rootViewController = mvc

    } else {
        globalClass.token = ""
        let mvc: LoginViewController = mainStoryBoard.instantiateViewControllerWithIdentifier("loginView") as! LoginViewController
        self.window?.rootViewController = mvc
    }
    self.window?.makeKeyAndVisible()

我的问题是,当我在加载时以编程方式将初始 view controller 设置为选项卡控制器的第一个选项卡时,底部的选项卡菜单不会加载。它只是加载view controller 而不是标签菜单。

MainViewController 是标签视图控制器的第一个标签

谢谢,

阿夫辛

【问题讨论】:

  • 你能发布你用来“设置初始视图控制器”的代码吗?另外,这个逻辑在你的项目中在哪里?应用代理?
  • 并在“else”语句中发布代码不起作用?这次编辑您的问题并将其发布在此处,而不是在 cmets 中。

标签: ios swift tabview


【解决方案1】:

试试这个代码。

let tbc = mainStoryBoard.instantiateViewControllerWithIdentifier("tabbarStoryboardId") as! UItabBarController self.window?.rootViewController = tbc

谢谢

【讨论】:

  • 谢谢我在更改程序后忘记更改“tabbarStoryboardId”。这是一个愚蠢的问题:|
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-05-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多