we7ee we7ee - 1 year ago 92
iOS Question

Call View from storyboard with UITabbarController and UINavigationController

I'm trying to implement the 3D quick action for my iOS app.
I've managed to add the quick actions and want to open a viewcontroller in my storyboard.

My root controller is an UITabbarController. Inside this I've an UINavigationController.

I've followed this tutorial

Then I want to open a search view in the appdelegate and I tried to do it like in the tutorial. But I only see a black screen.

func application(application: UIApplication, performActionForShortcutItem shortcutItem: UIApplicationShortcutItem, completionHandler: (Bool) -> Void) {
if shortcutItem.type == "com.traning.addStuff" {
let sb = UIStoryboard(name: "Main", bundle: nil)
let searchVC = sb.instantiateViewControllerWithIdentifier("Search") as! SearchView
let root = UIApplication.sharedApplication().keyWindow?.rootViewController

root?.presentViewController(searchVC, animated: false, completion: { () -> Void in


My viewcontroller is the third viewcontroller in my UINavigationController

[UITab] -> [UINav] -> [UINav] -> [UINav]

I've tried to initialize the root view as UITabbarController but how I can access or call my view as UINavigationController?

Any suggestions?

Thank you!


I've added an image to illustrate my Storyboard (it's just an example)
I have a UITabBarController -> UINavigationController -> FirstView -> SecondView

enter image description here

With the 3D Quick Actions I want call the SecondView.

Answer Source

For all who have the same problem I've found a solution here: http://blog.opendatalab.de/hack/2015/10/25/3d-touch-with-tabbarcontroller-and-navigationcontroller

So here is the code I used to call the secondView:

if let tabController = self.window?.rootViewController as? UITabBarController {
                tabController.selectedIndex = 1

                let navController = tabController.selectedViewController as? UINavigationController

                let firstView = navController?.viewControllers[0]
                firstView?.performSegueWithIdentifier("second", sender: nil)                

the tabController.selectedIndex is depending on the view item in your UITabBarController where you want to perform the segue. I my case it was the second item of the UITabBarController.

I hope this helps.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download