[英]viewDidLoad() is called every time after dismiss() of UIImagePickerController()
I presented UIImagePickerController()
from ViewControllerA
and when I select a image its delegate called and in that delegate I wrote 我从ViewControllerA
提供了UIImagePickerController()
,当我选择一个图像时,它的委托被调用,在该委托中我写了
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
dismiss(animated: true, completion: nil)
}
but viewDidLoad()
of ViewControllerA
also called 但是ViewControllerA
viewDidLoad()
也称为
Please find below code, viewDidLoad doesn't get called every time. 请查找以下代码,不会每次都调用viewDidLoad。
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. 如有任何疑问,请通知我。
When using the UIImagePickerViewController, often times the camera will cause a memory warning and your viewcontroller's viewDidUnload method will be called. 使用UIImagePickerViewController时,通常相机会发出内存警告,并且会调用您的viewcontroller的viewDidUnload方法。 Next time your view is shown (when the UIImagePickerViewController is dismissed), the viewDidLoad method will be called because it was previously unloaded. 下次显示视图时(关闭UIImagePickerViewController时),将调用viewDidLoad方法,因为该方法先前已卸载。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.