我正在尝试从主屏幕添加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>.
有没有办法让应用程序在维护标签栏和导航控制器的同时推送到“查找食物”视图控制器。谢谢!!
首先,将rootVC作为选项卡,然后导航应该来自内部
所以将tabBarControllber子类化,并在viewDidAppear中,根据应用程序内部的导航bool或逻辑进行推送
let foodVC = storyboard.instantiateViewController(withIdentifier: "FoodVC") as! BusStatusTableViewController
// here do segue to food VC
做了一些挖掘并找到了解决方案。我在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。