我的入职过程(登录/注册)位于UINavigationController链之外,但是当登录经过身份验证时,我在app委托中调用一个方法,该方法应该实例化rootViewController,然后推送到它。我试过两件事:
上面的代码片段在appDelegate中是从响应本地通知时被调用的方法中运行的,但在本例中不起作用。
self.window?.makeKeyAndVisible()
self.window?.rootViewController?.navigationController?.popToRootViewControllerAnimated(true)下面是我尝试过的另一种方法:
let rootViewController = self.window?.rootViewController
let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let dashboard = mainStoryboard.instantiateViewControllerWithIdentifier("DashboardViewController") as! DashboardViewController
rootViewController!.navigationController?.popToViewController(dashboard, animated: true)这两样都不管用。我做错了什么?
发布于 2015-09-29 14:21:58
我的登录视图控制器也在我的选项卡条控制器之外,所以这就是我所做的:

在appDelegate中:
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let loginVC = storyboard.instantiateViewControllerWithIdentifier("LoginVC") as! LoginViewController
self.window?.rootViewController = loginVC
self.window!.makeKeyAndVisible()
return true
}然后在我的loginViewContoller.swift中有一个方法:
@IBAction func loginPushed(sender: AnyObject) {
//other stuff here
let mainStoryBoard = UIStoryboard(name: "Main", bundle: nil)
let tabBarController = UITabBarController()
let first = mainStoryBoard.instantiateViewControllerWithIdentifier("firstNavController") as! UINavigationController
let second = mainStoryBoard.instantiateViewControllerWithIdentifier("secondNavController") as! UINavigationController
let third = mainStoryBoard.instantiateViewControllerWithIdentifier("thirdNavController") as! UINavigationController
let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate
let controllers = [first, second, third]
tabBarController.viewControllers = controllers
appDelegate.window!.rootViewController = tabBarController
appDelegate.window!.makeKeyAndVisible()
}发布于 2015-09-29 13:51:40
我认为您不应该调用“popToRootViewController”,您可以重新分配window.rootViewController~
https://stackoverflow.com/questions/32845348
复制相似问题