When using the 3D Touch keyboard shortcuts on the main screen, I try to switch to another view controller.
The application is built into the UITabBarController , and each root tab controller is a UINavigationController .
This is how I tried to handle shortcuts to load the view controller for each shortcut.
private func handleShortcutItem(shortcutItem: UIApplicationShortcutItem) { if let rootViewController = window?.rootViewController, let shortcutItemType = ShortcutItemType(shortcutItem: shortcutItem) { let sb = UIStoryboard(name: "main", bundle: nil) let helloVC = sb.instantiateViewControllerWithIdentifier("HelloVC") as! HelloViewController let goodbyeVC = sb.instantiateViewControllerWithIdentifier("GoodbyeVC") as! GoodbyeViewController switch shortcutItemType { case .Hello: rootViewController.presentViewController(helloVC, animated: true, completion: nil) break case .Goodbye: rootViewController.presentViewController(goodbyeVC, animated: true, completion: nil) break } } }
With this code, shortcuts open an application only to the initial view controller, and not to the helloVC and goodbyeVC , which are on different tabs.
I assume this is because the ViewControllers that I am trying to load is built into the UINavigationController and also built into the UITabBarController .
How can I presentViewController embed in UITabBarController and UINavigationController ?
UPDATE
I'm not sure the following works, as I don't have an iPhone 6S with me. But I changed the code to the next, hopefully this will load the selected tab index when 3D Touch Action is executed. From there, he should post a notification to the view manager to complete the session.
private func handleShortcutItem(shortcutItem: UIApplicationShortcutItem) { if let rootViewController = window?.rootViewController, let shortcutItemType = ShortcutItemType(shortcutItem: shortcutItem) { let tababarController = rootViewController as! UITabBarController switch shortcutItemType { case .Hello: tababarController.selectedIndex = 1 NSNotificationCenter.defaultCenter().postNotificationName("performsegueHello", object: nil) break case .Goodbye: tababarController.selectedIndex = 4 NSNotificationCenter.defaultCenter().postNotificationName("performsegueGoodbye", object: nil) break } } }
ios swift uitabbarcontroller uinavigationcontroller presentviewcontroller
RileyDev
source share