我正努力在xcode上更改个人资料图片。香港专业教育学院设法让应用程序从iOS上的照片库中更改带有照片的UIImageView,但是当我选择图像时,它发生了变化,然后向后退了UIViewController /上一个视图。
我不确定为什么要这样做以及代码在哪里出错了?有人可以帮忙吗?
import UIKit
class ProfileScreenVC: UIViewController, UINavigationControllerDelegate, UIImagePickerControllerDelegate {
@IBOutlet var imgProfilePic: UIImageView!
@IBAction func ChangeProfile(_ sender: AnyObject)
{
let PPimage = UIImagePickerController()
PPimage.delegate = self
PPimage.sourceType = UIImagePickerController.SourceType.photoLibrary
PPimage.allowsEditing = false
self.present(PPimage, animated: true)
{
// After it is complete
}
}
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any])
{
if let PPimage = info [UIImagePickerController.InfoKey.originalImage] as? UIImage
{
imgProfilePic.image = PPimage
}else{
//Error Message
}
self.dismiss(animated: true, completion: nil)
}
override func viewDidLoad() {
super.viewDidLoad()
// Make image circular
imgProfilePic.roundedImages()
// Do any additional setup after loading the view.
}
}
当发生这种情况时,我也会得到此错误/输出。
发现扩展名时遇到错误:错误Domain = PlugInKit Code = 13“查询已取消” UserInfo = {NSLocalizedDescription =查询已取消}
答案 0 :(得分:1)
不是关闭UIViewController
,而是关闭UIImagePickerController
(在这种情况下,您可以使用方法参数之一:picker
)
picker.dismiss(animated: true, completion: nil)