[英]Get Instance Of ViewController From AppDelegate In Swift
I am trying to load a specific ViewController from the app delegate in swift when a user clicks a UILocalNotification. 我试图在用户单击UILocalNotification时从swift中的app delegate加载特定的ViewController。 I have figured out that this is called in this function:
我已经发现在这个函数中调用了它:
func application(application: UIApplication!, didReceiveLocalNotification notification: UILocalNotification!)
But when I try and access one of the open ViewControllers I think it's returning null because my application is crashing. 但是当我尝试访问其中一个打开的ViewControllers时,我认为它返回null,因为我的应用程序崩溃了。 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()
It's crashing on the popToViewController line. 它在popToViewController行崩溃了。
You could try: 你可以尝试:
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 3: 斯威夫特3:
let mainStoryboard = UIStoryboard(name: "Main", bundle: nil)
let controller = mainStoryboard.instantiateViewController(withIdentifier: "viewController")
self.present(viewController, animated: true, completion: nil)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.