我正在尝试使用App Delegate来打开视图控制器,具体取决于选择了哪种快速操作,但是我想将“ Bar Controller”选项卡放在底部。到目前为止,我的代码是:
func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
let storyboard = UIStoryboard.init(name: "Main", bundle: nil)
let tabBarController = storyboard.instantiateViewController(withIdentifier: "TabBar") as! UITabBarController
let CLLViewC = storyboard.instantiateViewController(withIdentifier: "CLL")
let OLLViewC = storyboard.instantiateViewController(withIdentifier: "OLLStoryboard")
let PLLViewC = storyboard.instantiateViewController(withIdentifier: "PLL")
let desiredVC = storyboard.instantiateViewController(withIdentifier: "OLLStoryboard")
tabBarController.viewControllers = [CLLViewC, OLLViewC, PLLViewC]
if shortcutItem.type == "com.LukeB.Cubing-practice.OLL" {
OLLViewC.present(desiredVC, animated: true, completion: nil)
print("present")
}
}
这不起作用,并且出现错误Attempt to present <Cubing_practice.OLLViewController: 0x105803810> on <Cubing_practice.OLLViewController: 0x103f03c50> whose view is not in the window hierarchy!
尽管可以访问if语句,就像控制台确实说的那样,但是当我点击快速操作时打开的ViewController是默认的,就像我刚刚正常打开应用程序一样。
该如何解决?