Reputation: 428
I presented UIImagePickerController()
from ViewControllerA
and when I select a image its delegate called and in that delegate I wrote
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
dismiss(animated: true, completion: nil)
}
but viewDidLoad()
of ViewControllerA
also called
Upvotes: 0
Views: 467
Reputation: 6555
Please find below code, viewDidLoad doesn't get called every time.
override func viewDidLoad() {
super.viewDidLoad()
print("View Did Load")
}
private func imagePickerController(_ picker: UIImagePickerController,
didFinishPickingMediaWithInfo info: [String : AnyObject]) {
picker.dismiss(animated: true, completion: nil);
_ = info[UIImagePickerControllerOriginalImage] as! UIImage
}
func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
picker.dismiss(animated: true, completion: nil)
}
Open Photo Library using this code,
@IBAction func btnclicked(_ sender: Any) {
let picker = UIImagePickerController()
picker.sourceType = .photoLibrary
picker.delegate = self
self.present(picker, animated: true, completion: nil)
}
Also post some of your code so I can review it.
Let me know in case of any queries.
Upvotes: 1
Reputation: 5360
When using the UIImagePickerViewController, often times the camera will cause a memory warning and your viewcontroller's viewDidUnload method will be called. Next time your view is shown (when the UIImagePickerViewController is dismissed), the viewDidLoad method will be called because it was previously unloaded.
Upvotes: 0