【发布时间】:2015-03-13 01:50:17
【问题描述】:
我有一个带有初始登录屏幕的标签栏应用程序。 tabbarController 设置为 Storyboard 中的初始视图,其中包含 1 个还嵌入了 navigationController 的 VC。
我有一个 loginVC 实例化并在我的 AppDelegate 中设置为 rootViewController。用户从 loginVC 成功登录后,我需要切换到 tabbarController。我会尝试获取对 tabbarcontroller 的引用并将其设置为新的 rootviewcontroller 吗?如果是这样,我很难弄清楚如何做到这一点:/
AppDelegate
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
if NSUserDefaults.standardUserDefaults().objectForKey("OAuth") == nil {
self.window = UIWindow(frame:UIScreen.mainScreen().bounds)
var storyboard = UIStoryboard(name: "Main", bundle: nil)
var loginVC = storyboard.instantiateViewControllerWithIdentifier("LOGIN_VC") as LoginVC
self.window?.rootViewController = loginVC
self.window?.makeKeyAndVisible()
}
return true
}
用户成功登录后调用此方法
func dismissLoginVC() {
var tabbarController = self.storyboard?.instantiateViewControllerWithIdentifier("TABBAR") as UITabBarController
self.presentViewController(tabbarController, animated: true, completion: nil)
let appDelegate: AppDelegate = UIApplication.sharedApplication().delegate as AppDelegate
appDelegate.window?.rootViewController = tabbarController
}
我知道问题在于它只是创建了一个新的 tabbarcontroller,而不是引用在故事板中设置为 initialView 的现有 tabbarController。这似乎可行,但它缺少导航栏中的其他项目。
感谢您为我指明正确的方向!
【问题讨论】:
标签: ios swift uitabbarcontroller appdelegate