【发布时间】:2016-11-10 09:30:25
【问题描述】:
我第一次尝试在 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)
})
}
}
【问题讨论】:
-
请告诉我viewController是UIViewController还是UINavgitaionController?
-
这是 TabController,这实际上是错误...谢谢,现在可以使用