在Swift中从AppDelegate获取ViewController的实例
当用户单击UILocalNotification时,我试图迅速从应用程序委托中加载特定的ViewController。我已经知道这是在此函数中调用的:
func application(application: UIApplication!, didReceiveLocalNotification notification: UILocalNotification!)
但是当我尝试访问一个打开的ViewController时,我认为它返回null,因为我的应用程序崩溃了。这是我正在尝试的:
var rootViewController = self.window!.rootViewControllervar storyBoard = rootViewController.storyboard
var setViewController = storyBoard.instantiateViewControllerWithIdentifier("CurrentShows") as ViewController_CurrentShows
rootViewController.navigationController.popToViewController(setViewController, animated: false)
setViewController.reloadData()
在popToViewController行上崩溃了。
回答:
您可以尝试:
let rootViewController = self.window!.rootViewControllerlet mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let setViewController = mainStoryboard.instantiateViewControllerWithIdentifier("CurrentShows") as! DetailViewController
rootViewController?.navigationController?.popToViewController(setViewController, animated: false)
let mainStoryboard = UIStoryboard(name: "Main", bundle: nil)let controller = mainStoryboard.instantiateViewController(withIdentifier: "viewController")
self.present(viewController, animated: true, completion: nil)
以上是 在Swift中从AppDelegate获取ViewController的实例 的全部内容, 来源链接: utcz.com/qa/399581.html