I'm trying to go to any out of the 3 tab bar elements that I have in my storyboard depending on which quick action I select when 3D Touching on the app icon. I want to still be able to see the tab bar controller, which is where I've been struggling recently. Any help would be greatly appreciated.
Edit: I have got it to go to each separate Tab Bar Items.
I now need to activate the segue in each view, and here is the code that I'm using:
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
}
}
The behavior you are looking for is explained in the documentation for UIApplicationDelegate
's quick action handler here. To summarize, you need to check the launch options in your willFinishLaunching
or didFinishLaunching
and then decide what to do based on what you see.
The issue you're having could be caused by how you are setting the view that is first shown in your app. You might be setting the ViewController to the one that is nested into the tab view controller rather than setting it as the tab controller and then telling the tab controller which of its views to show.
That's just speculation, you'll need to share more code to get a more specific answer.
Update: Now that you have solved the problem of having the correct tab show, you want that view to segue another view on top of it.
The documentation for UITabBarController
gives some hints for how to do this in the section called "The Views of a Tab Bar Controller". One way to do what you are trying to do would be to set up your UIViewControllers
so that each tab has a navigation controller as a root. This way, you can push whichever controller you want onto the view in a way the user will recognize.
UINavigationController - Controller 1 -> push new controller
/
TBC - UINavigationController - Controller 2 -> push new controller
\
UINavigationController - Controller 3 -> push new controller
Alternatively, if you have a custom segue you want to use, you can continue with what you are doing with myTabBar?.selectedViewController.performSegue(withIdentifier:sender:)