Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/114.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 3d touch swift 3不会打开viewcontroller_Ios_Swift_Xcode_Appdelegate_3dtouch - Fatal编程技术网

Ios 3d touch swift 3不会打开viewcontroller

Ios 3d touch swift 3不会打开viewcontroller,ios,swift,xcode,appdelegate,3dtouch,Ios,Swift,Xcode,Appdelegate,3dtouch,我在我的应用程序代理中为shortcutitems提供了一个3d touch功能,当3d touch项从iphone上单击时,它必须实例化一个viewcontroller 代码如下: func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {

我在我的应用程序代理中为shortcutitems提供了一个3d touch功能,当3d touch项从iphone上单击时,它必须实例化一个viewcontroller

代码如下:

func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
        if shortcutItem.type == "com.kevinvugts.addStuf" {
            let sb = UIStoryboard(name: "Main", bundle: nil)
            let exerciseVC = sb.instantiateViewController(withIdentifier: "exerciseVC") as! exerciseVC
            let root = UIApplication.shared.keyWindow?.rootViewController
            root?.present(exerciseVC, animated: false, completion: { () -> Void in
                    completionHandler(true)
            })
        }
    }
此代码导致以下警告/错误:

Warning: Attempt to present <ActiveRest.exerciseVC: 0x131d39320> on <ActiveRest.ViewController: 0x131d0e470> whose view is not in the window hierarchy!
警告:尝试显示其视图不在窗口层次结构中的对象!
这和耽搁有关吗

谢谢你的帮助


问候。

视图不在窗口层次结构中
,这意味着您的viewcontroller的
视图仍没有加载到内存中。因此,您无法在其上显示
viewcontroller
。您应该必须从
viewdide显示
viewcontroller的
viewcontroller(我的意思是从您的rootviewController)


我做了此更改,一切正常。

但这是在应用程序委派中调用的。您不能从
appdelegate
显示viewcontroller,因为您的
viewHierarchy
appdelegate
中未准备就绪!我观看了本教程,并做了完全相同的操作:
func application(_ application: UIApplication, performActionFor shortcutItem: UIApplicationShortcutItem, completionHandler: @escaping (Bool) -> Void) {
    if shortcutItem.type == "com.kevinvugts.addStuf" {
        let sb = UIStoryboard(name: "Main", bundle: nil)
        let exerciseVC = sb.instantiateViewController(withIdentifier: "exerciseVC") as! exerciseVC
        window?.rootViewController?.addChildViewController(exerciseVC)

    }
}