Swift 4 - 带标签栏的3D触摸快速操作&导航控制器

时间:2018-03-02 16:55:41

标签: ios swift xcode 3dtouch

我正在尝试从主屏幕添加3D Touch Quick Actions,我正在使用以下代码:

        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let tabVC = storyboard.instantiateViewController(withIdentifier: "TabVC") as! UITabBarController
        let mainVC = storyboard.instantiateViewController(withIdentifier: "NavMoreVC") as! UINavigationController
        let foodVC = storyboard.instantiateViewController(withIdentifier: "FoodVC") as! FoodTableViewController
        window?.rootViewController = tabVC
        self.window?.makeKeyAndVisible()
        mainVC.pushViewController(foodVC, animated: true)

我试图在用户点击快捷方式后导航到Find Food视图控制器,但上面的代码在控制台中给出了错误:

Unbalanced calls to begin/end appearance transitions for <UITabBarController: 0x10e022600>.

在维护标签栏和导航控制器的同时,应用程序是否可以推送到“查找食物”视图控制器。谢谢!

Navigation Structure

2 个答案:

答案 0 :(得分:1)

首先,将rootVC作为选项卡,然后导航应该来自内部

所以将tabBarControllber作为子类,并在viewDidAppear中,根据导航bool或应用程序内共享的逻辑进行推送

    let foodVC = storyboard.instantiateViewController(withIdentifier: "FoodVC") as! BusStatusTableViewController
    // here do segue to food VC

答案 1 :(得分:1)

进行了一些挖掘并找到了解决方案。我在AppDelegate中使用了以下代码:

    let myTabBar = self.window?.rootViewController as? UITabBarController
    myTabBar?.selectedIndex = 0
    let nvc = myTabBar?.selectedViewController as? UINavigationController
    let vc = nvc?.viewControllers.first as? MoreViewController
    nvc?.popToRootViewController(animated: false)
    return vc!.openPageFor(shortcutIdentifier: shortcutIdentifier)

然后在我的MoreViewController中,我有一个函数,它将根据shortcutIdentifier调用不同的segue。