Search code examples
iosswiftxcodetouch

AppDelegate Touch3D Xcode - TabBar


I'm trying to implement 3D Touch in xcode 7.3.1 in swift 2 for the first time. I inserted the information in info.plist, up to here works as you can see from code to open the view works, the problem is that I do not view the TabBar ... so I decided to change everything, open the tab controller, and then move from there type in the section with selectindex = 2, but do not know how to do ... the select index function AppDelegate with work, someone can help me?

This is my code in AppDelegate to manage 3D Touch

func application(application: UIApplication, performActionForShortcutItem shortcutItem: UIApplicationShortcutItem, completionHandler: Bool -> Void) {
        //questo codice verrà eseguito ogni volta che le Quick Actions verranno eseguite
        if (shortcutItem.type == "com.tuu.openSearch") {
          //section search THIS WORK without TabBar!!
            let viewcontroller = UIStoryboard.init(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("searchID")
            dispatch_async(dispatch_get_main_queue(), {
                self.window!.rootViewController?.presentViewController(viewcontroller, animated: false, completion: nil)
            })

        }
        if (shortcutItem.type == "com.tuu.openFavorite"){
            //section tabbar favorite, self.tabBarcontroller.selectedIndex = 2 not work!!
            let viewcontroller = UIStoryboard.init(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("favoritesID")
            viewcontroller.tabBarController?.selectedIndex = 2
            dispatch_async(dispatch_get_main_queue(), {
                self.window!.rootViewController?.presentViewController(viewcontroller, animated: false, completion: nil)

            })
        }
    }

Solution

  • solved

    if (shortcutItem.type == "com.tuu.openFavorite"){
                let tabBarController = UIStoryboard.init(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("favoritesID") as! UITabBarController
                tabBarController.selectedIndex = 2
                self.window?.rootViewController = tabBarController
    
            }