如何在Delegate中引用其他ViewControllers而不仅仅是root

问题描述 投票:0回答:1

我正在尝试创建一个Siri Shortcut,我希望快捷方式可以转到另一个ViewController,而不仅仅是root。怎么做的?以下是当前的App Delegate代码。

func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([Any]?) -> Void) -> Bool {

            print(userActivity.activityType)//com.myvisionapps.Meditate.begin
            if(userActivity.activityType == "com.myvisionapps.Meditate.begin") {
                if let controller = window?.rootViewController as? ViewController {

                }

            }

            return false


        }
ios swift
1个回答
0
投票

你可以使用这个代码AppDelegate,它变得很好:

let mainStoryboardIpad : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let initialViewControlleripad : yourViewController = mainStoryboardIpad.instantiateViewController(withIdentifier: "yourViewControllerIdentifire") as! yourViewController
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.rootViewController = initialViewControlleripad
self.window?.makeKeyAndVisible()
// now you can use initialViewControlleripad to access to your references in your ViewController
© www.soinside.com 2019 - 2024. All rights reserved.