我正在尝试呈现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并从按钮调用它,在点击它后,图像选择器会出现,但应用程序突然崩溃并出现以下错误:
CaptureImageViewController respondsToSelector:]: message sent to deallocated instance 0x7960b1e0
我正在使用 XCode Beta 6 开发模拟器
任何想法?