gpt4 book ai didi

ios - 呈现 UIImagePickerController 后应用程序崩溃

转载 作者:行者123 更新时间:2023-11-28 09:19:59 25 4
gpt4 key购买 nike

我试图呈现一个 UIImagePickerController 以便从相册中获取图像,但我遇到了一个奇怪的行为。

如果我在 viewDidLoad 中启动图像选择器,它会工作:

class CaptureImageViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {

@IBOutlet weak var imageView: UIImageView!

override func viewDidLoad() {
super.viewDidLoad()
initPicker()
}

func initPicker() {
let picker = UIImagePickerController()
picker.delegate = self
picker.sourceType = UIImagePickerControllerSourceType.PhotoLibrary
presentViewController(picker, animated: true, completion: nil)
}

func imagePickerController(picker: UIImagePickerController!, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]!) {
dismissViewControllerAnimated(true, completion: nil)
imageView.image = info["UIImagePickerControllerOriginalImage"] as UIImage
}

func imagePickerControllerDidCancel(picker: UIImagePickerController!) {
dismissViewControllerAnimated(true, completion: nil)
}

}

但是,如果我将 initPicker() 转换为 @IBAction 并从 Button 调用它,在点击它之后,图像选择器会出现,但应用程序会突然崩溃出现此错误:

CaptureImageViewController respondsToSelector:]: message sent to deallocated instance 0x7960b1e0

我正在使用 XCode Beta 6 开发模拟器

有什么想法吗?

最佳答案

尝试将 UIImagePickerController 的对象声明为 Instance 级别参数,而不是在函数内声明。

关于ios - 呈现 UIImagePickerController 后应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25564501/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com