我第一次尝试在 swift 2 中的 xcode 7.3.1 中实现 3D Touch。我在 info.plist 中插入了信息,到这里为止你可以从代码中看到打开 View 的工作方式,问题是我没有查看 TabBar ...所以我决定改变一切,打开选项卡 Controller ,然后从那里开始输入 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)
})
}
}
最佳答案
解决了
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
}
关于ios - AppDelegate Touch3D Xcode - TabBar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40524076/