c_rath的答案基本上是正确的,但是您无需将视图控制器设为根视图控制器。实际上,即使从App
Delegate,您也可以在导航堆栈的顶视图和任何其他视图控制器之间触发选择。例如,要推送情节提要视图控制器,您可以执行以下 *** 作:
Swift 3.0及更高版本
// Access the storyboard and fetch an instance of the view controllerlet storyboard = UIStoryboard(name: "Main", bundle: nil);let viewController: MainViewController = storyboard.instantiateViewController(withIdentifier: "ViewController") as! MainViewController;// Then push that view controller onto the navigation stacklet rootViewController = self.window!.rootViewController as! UINavigationController;rootViewController.pushViewController(viewController, animated: true);
Swift 2.0及更早版本
// Access the storyboard and fetch an instance of the view controllervar storyboard = UIStoryboard(name: "Main", bundle: nil)var viewController: MainViewController = storyboard.instantiateViewControllerWithIdentifier("ViewController") as MainViewController// Then push that view controller onto the navigation stackvar rootViewController = self.window!.rootViewController as UINavigationControllerrootViewController.pushViewController(viewController, animated: true)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)