Reputation: 7
i am struggling with changing a profile picture on xcode. Ive managed to get the app to change a UIImageView with photo from the photo library on IOS however when i select the image, it changes then goes backwards a UIViewController/previous view.
Im not sure why it is doing this and where i have gone wrong in the code? can someone help?
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.
}
}
I also get this error/output when this happens too.
errors encountered while discovering extensions: Error Domain=PlugInKit Code=13 "query cancelled" UserInfo={NSLocalizedDescription=query cancelled}
Upvotes: 0
Views: 261
Reputation: 11150
Instead of dismissing your UIViewController
dismiss just UIImagePickerController
(in this case you can use one of the method parameters: picker
)
picker.dismiss(animated: true, completion: nil)
Upvotes: 1