我正在尝试在用户单击UILocalNotification时从swift中的app delegate加载特定的ViewController。我已经发现在这个函数中调用了它:
func application(application: UIApplication!, didReceiveLocalNotification notification: UILocalNotification!)
但是当我尝试访问其中一个打开的ViewControllers时,我认为它因为我的应用程序崩溃而返回null。这是我正在尝试的:
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行崩溃了。
答案 0 :(得分:25)
你可以尝试:
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)
斯威夫特3:
let mainStoryboard = UIStoryboard(name: "Main", bundle: nil)
let controller = mainStoryboard.instantiateViewController(withIdentifier: "viewController")
self.present(viewController, animated: true, completion: nil)