OGeek|极客世界-中国程序员成长平台

标题: ios - 从 AppDelegate 呈现一个 ViewController [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 18:38
标题: ios - 从 AppDelegate 呈现一个 ViewController

我在 Info.plist 中设置了 3D Force Touch Action。现在我希望当 3D Action 运行时它会显示一个 View Controller ,我提供了一个 Storyboard ID,我需要在 AppDelegate 中执行此操作。

我使用了 performActionForShortCutItem 函数。

func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
    if let tabVC = self.window?.rootViewController as? UITabBarController {
        if shortcutItem.type == "Hausaufgaben" {
            tabVC.selectedIndex = 1
            tabVC.performSegue(withIdentifier: "gotoHausaufgaben", sender: nil)
        }    
    }        
}



Best Answer-推荐答案


func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
   if shortcutItem.type == "Hausaufgaben" {
      self.window = UIWindow(frame: UIScreen.main.bounds)
      let storyboard = UIStoryboard(name: "Main", bundle: nil)
      let initialViewController = storyboard.instantiateViewController(withIdentifier: "YOUR PAGE Identifier")
      self.window?.rootViewController = initialViewController
      self.window?.makeKeyAndVisible()
   }
}

关于ios - 从 AppDelegate 呈现一个 ViewController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41771390/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4