ios - 3d touch swift 3 不打开viewcontroller

标签 ios swift xcode appdelegate 3dtouch

我的应用程序委托(delegate)中有一个 3d 触摸功能用于快捷方式,当从 iphone 中点击 3d 触摸项目时,它必须实例化一个 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!

这与延迟有什么关系吗?

感谢您的帮助!

亲切的问候。

最佳答案

view is not in the window hierarchy 这意味着你的 viewcontroller 的 View 还没有加载到内存中。所以你无法在上面显示 viewcontroller。您应该从 viewcontroller(我的意思是从您的 rootviewController)viewDidAppear 显示 viewcontroller。

关于ios - 3d touch swift 3 不打开viewcontroller,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40174580/

相关文章:

android - Corona SDK 应用程序大小太大

ios - 如何在默认共享对话框中包含 Facebook Messenger 和 Instagram?

ios - 快速 xcode 从导航 Controller 切换到标签栏 Controller 的正确方法

ios - 将 Label 放入空的垂直 StackView 中会自动缩小堆栈

iphone - 如何更新ios?

ios - 我的 UINavigationControllerDelegate 在应用加载主视图后被取消了

ios - 在另一个类中时,Swift Firebase 身份验证不起作用

json - 在 Swift 5.1 中循环多维/嵌套 JSON 数据

iOS 应用上传到应用商店无效的配置文件

ios - 状态栏在ios 7中的 View 上重叠