gpt4 book ai didi

ios - 在 Swift 中从 AppDelegate 获取 ViewController 的实例

转载 作者:IT王子 更新时间:2023-10-29 05:13:18 25 4
gpt4 key购买 nike

当用户单击 UILocalNotification 时,我正在尝试从 app delegate 中快速加载特定的 ViewController。我发现这是在这个函数中调用的:

func application(application: UIApplication!, didReceiveLocalNotification notification: UILocalNotification!)

但是当我尝试访问其中一个打开的 ViewController 时,我认为它返回 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 行上崩溃。

最佳答案

你可以试试:

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:

let mainStoryboard = UIStoryboard(name: "Main", bundle: nil)
let controller = mainStoryboard.instantiateViewController(withIdentifier: "viewController")
self.present(viewController, animated: true, completion: nil)

关于ios - 在 Swift 中从 AppDelegate 获取 ViewController 的实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24638376/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com