从图库中选取图像后呈现视图控制器

时间:2017-10-26 11:13:49

标签: ios swift

我想在我从图库中选择图像后呈现一个视图控制器我收到此警告:尝试在视图不在窗口层次结构中呈现!

任何人都可以帮忙解决这个问题

我的代码是

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String: Any]) {
        dismiss(animated: true, completion: nil)

        if (info[UIImagePickerControllerOriginalImage] as? UIImage) != nil {
            print(info)
            if let manageDocumentController = self.storyboard?.instantiateViewController(withIdentifier: "ManageDocumentVC")
                as? ManageDocumentVC {
                let navController = SMNavigationController(rootViewController: manageDocumentController)
                self.present(navController, animated: true, completion: nil)
            }
        }
    }

1 个答案:

答案 0 :(得分:0)

如果要呈现给viewController,则应使用以下代码:

if let manageDocumentController = self.storyboard?.instantiateViewController(withIdentifier: "ManageDocumentVC") as? ManageDocumentVC {
   self.present(manageDocumentController, animated: true, completion: nil)
}

如果你的viewController有NavigationController,你应该使用下一个代码:

if let navController = self.storyboard?.instantiateViewController(withIdentifier: "nameOfNavigationControllerIdentifier") {
   self.present(navController, animated: true, completion: nil)
}