首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >didReceiveRemoteNotification presentViewController

didReceiveRemoteNotification presentViewController
EN

Stack Overflow用户
提问于 2016-05-24 09:36:58
回答 1查看 155关注 0票数 0

当推送通知到达时,我一直试图在我的应用程序上打开一个特定的视图,但是这个视图是通过一个拆分视图的详细视图来模式显示的,而且我无法做到。

这是我的故事板

我已经尝试过关于这个主题的许多答案中的一个,它只是介绍EventsViewController,但很明显,这种方式使VC变得孤立,不再连接到拆分视图。

代码语言:javascript
复制
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) { 
    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let navigationController = storyboard.instantiateViewControllerWithIdentifier("NavigationControllerMessages") as! UINavigationController
    let dVC:MessagesViewController = navigationController.topViewController as! MessagesViewController
    dVC.vehicleLicensePlate = "ABC"
    dVC.vehicleName = "My car"
    self.window?.rootViewController?.presentViewController(navigationController, animated: true, completion: {})

}

此外,我还尝试展示了实际工作的拆分视图,但我不知道如何爬上层次视图才能到达EventsViewController:

代码语言:javascript
复制
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let destinationViewController = storyboard.instantiateViewControllerWithIdentifier("SplitInStoryboard") as! SplitViewController
    self.window?.rootViewController?.presentViewController(destinationViewController, animated: true, completion:nil)

}

问题是如何表示EventsViewController,以便将根视图控制器和我的视图之间的所有视图连接起来?

希望有人能帮我求你。我为这件事挣扎了好几个小时。提前感谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-05-30 11:05:00

我终于找到答案了!这是基于@StepanGeneralov的答案https://stackoverflow.com/a/21297223/6144027。我把它贴在这里是因为总有一天这个可能会对某人有帮助。

代码语言:javascript
复制
    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let mvc = storyboard.instantiateViewControllerWithIdentifier("MessagesInStoryboard") as! MessagesViewController
    mvc.vehicleName = "My car"
    mvc.vehicleLicensePlate = "ABC"
    let navController = UINavigationController(rootViewController: mvc) // Creating a navigation controller for mvc

    var topRootViewController : UIViewController! = self.window?.rootViewController
    while let vvc = topRootViewController.presentedViewController{
        topRootViewController = vvc

    }
    topRootViewController.presentViewController(navController, animated: true, completion: nil)

顺便说一句,正如@guillaume所指出的,我们应该实现application:didReceiveRemoteNotification:fetchCompletionHandler:,而不仅仅是didReceiveRemoteNotification。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37409719

复制
相关文章

相似问题

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