通过App Delegate快速执行Segue

通过App Delegate快速执行Segue,第1张

通过App Delegate快速执行Segue

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)


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5171610.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-18
下一篇 2022-11-18

发表评论

登录后才能评论

评论列表(0条)

保存