从Swift中的AppDelegate获取ViewController的实例 [英] Get Instance Of ViewController From AppDelegate In Swift
本文介绍了从Swift中的AppDelegate获取ViewController的实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试在用户单击UILocalNotification时从swift中的app delegate加载特定的ViewController。我已经发现这是在这个函数中调用的:
I am trying to load a specific ViewController from the app delegate in swift when a user clicks a UILocalNotification. I have figured out that this is called in this function:
func application(application: UIApplication!, didReceiveLocalNotification notification: UILocalNotification!)
但是当我尝试访问其中一个打开的ViewControllers时,我认为它返回null因为我的应用程序崩溃了。这是我正在尝试的:
But when I try and access one of the open ViewControllers I think it's returning null because my application is crashing. Here is what I am trying:
var rootViewController = self.window!.rootViewController
var storyBoard = rootViewController.storyboard
var setViewController = storyBoard.instantiateViewControllerWithIdentifier("CurrentShows") as ViewController_CurrentShows
rootViewController.navigationController.popToViewController(setViewController, animated: false)
setViewController.reloadData()
它在popToViewController行崩溃。
It's crashing on the popToViewController line.
推荐答案
您可以尝试:
let rootViewController = self.window!.rootViewController
let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let setViewController = mainStoryboard.instantiateViewControllerWithIdentifier("CurrentShows") as! DetailViewController
rootViewController?.navigationController?.popToViewController(setViewController, animated: false)
这篇关于从Swift中的AppDelegate获取ViewController的实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文