I am trying to add 3D Touch Quick Actions from the home screen and I am using the following code:
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)
I'm trying to navigate to the Find Food view controller after the user tapped on the shortcut, but the code above gives me an error in the console:
Unbalanced calls to begin/end appearance transitions for <UITabBarController: 0x10e022600>.
Is there a way for the app to push to the Find Food view controller while maintaining the Tab Bar and Navigation Controllers. Thanks!!
First you make the rootVC as the tab then the navigate should be from inside it
so subclass the tabBarControllber and in viewDidAppear , do the push according to navigate bool or logic shared inside your app
let foodVC = storyboard.instantiateViewController(withIdentifier: "FoodVC") as! BusStatusTableViewController
// here do segue to food VC
Did some more digging and found the solution to it. I used the following code in the 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)
Then inside my MoreViewController I had a function that will call the different segues based on the shortcutIdentifier.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.