有我故事板的这一部分:
所以我想要来自UserProfileController:UIViewController“Мойпрофиль”,这是模态的,(在图像的顶部)UIImageViewController。
我的代码:
extension UserProfileController: UIImagePickerControllerDelegate, UINavigationControllerDelegate {
@IBAction func imagePressed(_ sender: Any) {
let imagePickerController = UIImagePickerController()
imagePickerController.delegate = self
self.present(imagePickerController, animated: true, completion: nil)
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
guard let image = info[UIImagePickerControllerOriginalImage] as? UIImage else {
return
}
picker.dismiss(animated: true, completion: nil)
userProfileImageView.image = image
}
}
嗯,imagePickerController出现了,但是在我选择了图像后,我已经解散了两个控制器(imagePickerController和parent - UserProfileControler)。
我做错了什么?感谢
P.S。可能是问题是我将“SideMenuNavigationController”显示为模态? (在SideMenu框架文档中建议)
答案 0 :(得分:0)
尝试在您的类中创建UIImagePickerController引用(作为变量)
// to choose an image from the Camera Roll
fileprivate lazy var imagePicker: UIImagePickerController = {
let picker: UIImagePickerController = UIImagePickerController()
picker.allowsEditing = false
picker.sourceType = .savedPhotosAlbum
picker.delegate = self
return picker
}()