アプリに 3D Touch ショートカットを実装しようとしていますが、タブ バー内にナビゲーション バーがあるという事実を処理する方法がわかりません。rootViewController をナビゲーション バーとして宣言すると、ショートカットが機能しますが、ショートカット画面が閉じられ、タブバーがありません。これが私のストーリーボードのリンク方法です。ここで何をすべきかわかりません。
私は赤に到達しようとしています。
@available(iOS 9.0, *)
func handleShortCutItem(shortcutItem: UIApplicationShortcutItem) -> Bool {
var handled = false
if let shortcutType = ShortcutType.init(rawValue: shortcutItem.type) {
let tabBarController = UITabBarController()
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let rootController = storyboard.instantiateViewControllerWithIdentifier("MainTabBar") as! UITabBarController
let tradesNav = storyboard.instantiateViewControllerWithIdentifier("TradeNavigation")
// if self.window != nil {
self.window!.rootViewController = rootController
// }
// Get root navigation view controller and its first controller
let rootNavigationViewController = window!.rootViewController as? UINavigationController
let rootViewController = rootNavigationViewController?.viewControllers.first as UIViewController?
// Pop to root view controller so segue can be handled
rootNavigationViewController?.popToRootViewControllerAnimated(true)
switch shortcutType {
case .newTrade:
tradesNav.performSegueWithIdentifier("newTradeModal", sender: nil)
handled = true
}
}
return handled
}
