splitView 中的 didReceiveRemoteNotification presentViewController
Posted
技术标签:
【中文标题】splitView 中的 didReceiveRemoteNotification presentViewController【英文标题】:didReceiveRemoteNotification presentViewController within splitView 【发布时间】:2016-05-24 09:36:58 【问题描述】:当推送通知到达时,我一直试图在我的应用程序上打开特定视图,但是这个视图正在以模式显示为拆分视图的详细视图,我无法做到。
This is my story board
我已经尝试了有关该主题的众多答案之一,即仅呈现 EventsViewController,但显然这种方式使 VC 处于孤立状态,不再连接到拆分视图。
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:
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 以便我可以连接根视图控制器和我的视图之间的所有视图?
希望任何人都可以帮助我,拜托。我已经为此苦苦挣扎了好几个小时。提前致谢!
【问题讨论】:
我认为您不应该在didReceiveRemoteNotification
中执行那种操作,因为可以在运行时随时调用此委托;任意推送视图控制器可能会中断用户的交互。此外,Apple Framework Reference 说您应该引用“尽可能实现application:didReceiveRemoteNotification:fetchCompletionHandler:
方法而不是这个方法。”
很公平,@guillaume。谢谢!但是,即使我实现了 application:didReceiveRemoteNotification:fetchCompletionHandler:,我仍然必须实现它将打开我的 EventsViewController 的完成处理程序块,而我最初的问题仍然存在,我该如何呈现 EventsViewController?
【参考方案1】:
我终于找到答案了!它基于@StepanGeneralov 的回答https://***.com/a/21297223/6144027。我把它贴在这里是因为有一天这可能会对某人有所帮助。
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。
【讨论】:
以上是关于splitView 中的 didReceiveRemoteNotification presentViewController的主要内容,如果未能解决你的问题,请参考以下文章
为啥弹出嵌套在 UISplitViewController 中的 UINavigationController 的控制器会为整个 splitView 设置动画?
IOS SplitView TableViewController 查询