当推送通知到达时,我一直试图在我的应用程序上打开一个特定的视图,但是这个视图是通过一个拆分视图的详细视图来模式显示的,而且我无法做到。
这是我的故事板
我已经尝试过关于这个主题的许多答案中的一个,它只是介绍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,以便将根视图控制器和我的视图之间的所有视图连接起来?
希望有人能帮我求你。我为这件事挣扎了好几个小时。提前感谢!
发布于 2016-05-30 11:05:00
我终于找到答案了!这是基于@StepanGeneralov的答案https://stackoverflow.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。
https://stackoverflow.com/questions/37409719
复制相似问题