从AppDelegate呈现一个ViewController

时间:2017-01-20 19:57:28

标签: ios swift 3dtouch

我在Info.plist设置了3D力量触摸动作。现在我希望在3D Action运行时它提供了一个视图控制器,我提供了一个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)
        }    
    }        
}

1 个答案:

答案 0 :(得分:0)

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