Shortcut Items - Perform Segue

71 views Asked by At

I'm trying to add a shortcut item to my app. I have the item appearing, and it's responding but can't work out how to get the segue to work. I have it going to the right tab but need to go to the root view and perform a segue from there.

The segue is already setup on the ProjectList view controller and its called "addProject"

My view storyboard is setup as so: UITabViewController -> UINavigationController-> UITableViewController (ProjectList) -> Other additional views

func applicationDidBecomeActive(_ application: UIApplication) {
    if let shortcutItem = shortcutItemToProcess {
        if shortcutItem.type == "addProject" {
            if let window = self.window, let tabBar : UITabBarController = window.rootViewController as? UITabBarController {
                tabBar.selectedIndex = 0
                
            }
        }
        shortcutItemToProcess = nil
    }
}
1

There are 1 answers

0
Ceri Turner On BEST ANSWER

Solved with

func applicationDidBecomeActive(_ application: UIApplication) {
    if let shortcutItem = shortcutItemToProcess {
        if shortcutItem.type == "addProject" {
            guard let window = self.window else { return }
            guard let tabBar = window.rootViewController as? UITabBarController else { return }
            guard let navCon = tabBar.viewControllers?[0] as? UINavigationController else { return }
            guard let projectList = navCon.rootViewController as? ProjectList else { return }
            
            projectList.performSegue(withIdentifier: "addProject", sender: nil)
            
            
            tabBar.selectedIndex = 0
        }
        shortcutItemToProcess = nil
    }
}