快捷方式-执行Segue

时间:2020-10-12 15:40:12

标签: swift xcode uiapplicationshortcutitem

我正在尝试向我的应用添加快捷方式项。我正在显示该项目,并且正在响应,但无法确定如何使Segue正常工作。我将其转到右侧的选项卡,但需要转到根视图并从那里执行segue。

segue已经在ProjectList视图控制器上设置,其名称为“ addProject”

我的视图故事板的设置如下: UITabViewController-> UINavigationController-> UITableViewController(ProjectList)->其他其他视图

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 个答案:

答案 0 :(得分:0)

解决了

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
    }
}