AppDelegate Touch3D Xcode - TabBar

时间:2016-11-10 09:30:26

标签: ios swift xcode touch

我第一次尝试在swift 2中的xcode 7.3.1中实现3D Touch。我在info.plist中插入了信息,到目前为止你可以从代码中看到打开视图的工作原理,问题是我没有查看TabBar ...所以我决定改变一切,打开标签控制器,然后从那里用selectindex = 2中的那个类型移动,但是不知道该怎么做...选择索引函数AppDelegate有工作,有人可以帮帮我吗?

这是AppDelegate中用于管理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)

            })
        }
    }

1 个答案:

答案 0 :(得分:0)

解决

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

        }