首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用UserNotifications didReceive响应演示ViewController

使用UserNotifications didReceive响应演示ViewController
EN

Stack Overflow用户
提问于 2017-07-12 20:37:16
回答 1查看 230关注 0票数 0

我有一个实现了UserNotifications的LocalNotification类。我已经在我需要展示的初始ViewController和CheckViewController之间创建了段。这是我的didReceive responce函数

func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) { let storyboard = UIStoryboard(name: "Main", bundle: nil) let nav = storyboard.instantiateInitialViewController() as! UINavigationController let mainViewController = nav.topViewController as! ViewController mainViewController.performSegue(withIdentifier: "CheckSegue", sender: nil) }

但我得到的仍然是初始的ViewController。我哪里错了?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-07-12 20:45:33

MainViewController是最初的视图控制器吗?如果是,那么您看到的实例就是应用程序的根目录。您正在创建一个不可见的全新实例。

试一试

代码语言:javascript
复制
let nav = UIApplication.shared.keyWindow?.rootViewController as? UINavigationController

而不是

代码语言:javascript
复制
let nav = storyboard.instantiateInitialViewController() as! UINavigationController
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45057904

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档