![](/img/trans.png)
[英]Swift 4 - 3D Touch Quick Actions With Tab Bar & Navigation Controller
[英]How to go to specific tab bar view via 3D Touch quick items
我試圖轉到情節提要中3個選項卡欄元素中的任何一個,具體取決於我在應用程序圖標上進行3D觸摸時選擇了哪種快速操作。 我仍然希望能夠看到標簽欄控制器,這是我最近一直在努力的地方。 任何幫助將不勝感激。
編輯:我有它去每個單獨的選項卡欄項。
現在,我需要在每個視圖中激活segue,這是我正在使用的代碼:
func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
let myTabBar = self.window?.rootViewController as? UITabBarController
let NavigationController = UINavigationController.self
if shortcutItem.type == "com.LukeB.Quick-Actions-Test.Three" {
myTabBar?.selectedIndex = 2
//Need to go to the segue with identifier SegueThree
}
if shortcutItem.type == "com.LukeB.Quick-Actions-Test.Two" {
myTabBar?.selectedIndex = 1
//Need to go to the segue with identifier SegueThree
}
if shortcutItem.type == "com.LukeB.Quick-Actions-Test.One" {
myTabBar?.selectedIndex = 0
//Need to go to the segue with identifier SegueOne
}
}
UIApplicationDelegate
的快速操作處理程序的文檔在此處說明了您要尋找的行為。 總而言之,您需要檢查willFinishLaunching
或didFinishLaunching
的啟動選項,然后根據所看到的內容決定要做什么。
您遇到的問題可能是由您如何設置應用程序中首次顯示的視圖引起的。 您可能將ViewController設置為嵌套在選項卡視圖控制器中的那個,而不是將其設置為選項卡控制器,然后告訴選項卡控制器顯示哪個視圖。
這僅僅是猜測,您需要共享更多代碼才能獲得更具體的答案。
更新:現在,您已經解決了顯示正確的選項卡的問題,您希望該視圖在其上方選擇另一個視圖。
UITabBarController
的文檔在“標簽欄控制器的視圖”部分中提供了一些有關如何執行此操作的提示。 執行您要執行的操作的一種方法是設置UIViewControllers
以使每個選項卡都將導航控制器作為根。 這樣,您可以以用戶將識別的方式將所需的任何控制器推入視圖。
UINavigationController - Controller 1 -> push new controller
/
TBC - UINavigationController - Controller 2 -> push new controller
\
UINavigationController - Controller 3 -> push new controller
或者,如果您要使用自定義序列,則可以繼續使用myTabBar?.selectedViewController.performSegue(withIdentifier:sender:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.