这是我的代码,一个简单的类,其中包含一个在storyboard中创建的视图,其中包含一个用于显示imagePickerView的按钮。将呈现imagePickerView,然后应用程序崩溃libc++abi.dylib: terminating with uncaught exception of type NSException
import Foundation
import UIKit
class ImageSelectionView: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
override func viewDidLoad(){
super.viewDidLoad()
}
@IBAction func backButtonTapped(_ sender: AnyObject) {
self.navigationController?.dismiss(animated: true, completion: nil)
}
@IBAction func openPhotoLibrary(_ sender: AnyObject) {
if UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.photoLibrary) {
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
imagePicker.sourceType = UIImagePickerControllerSourceType.photoLibrary;
imagePicker.allowsEditing = true
present(imagePicker, animated: true, completion: nil)
self.present(imagePicker, animated: true, completion: nil)
}
}
func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: [NSObject : AnyObject]!) {
self.dismiss(animated: true, completion: nil);
}
}
无法弄清楚这出错的地方,任何帮助都会很棒,谢谢!
答案 0 :(得分:2)
要访问照片库,您需要将Privacy - Photo Library Usage Description
放入应用程序的.plist
文件中,并附上一些说明,
如图所示
特别是在您的代码中,您已编写代码以呈现相同的imagePicker两次,如下所示。
present(imagePicker, animated: true, completion: nil)
self.present(imagePicker, animated: true, completion:
因此我建议保留一个,可能是present(imagePicker, animated: true, completion: nil)
OR
self.present(imagePicker, animated: true, completion:nil)
希望它有所帮助。
快乐的编码......
答案 1 :(得分:0)
当你调用imagepicker委托方法时,你的语法是错误的,然后一个viewcontroller被预先选择图像所以替换
present(imagePicker, animated: true, completion: nil)
self.present(imagePicker, animated: true, completion: nil)
使用
self.presentViewController(imagePicker, animated: true, completion: nil)
并且你没有在你的imageview中显示图像
func imagePickerController(picker: UIImagePickerController, didFinishPickingImage image: UIImage!, editingInfo: [NSObject : AnyObject]!) {
"YOUR IMAGEVIEW".image = info[UIImagePickerControllerOriginalImage] as? UIImage
self.dismiss(animated: true, completion: nil);
}
答案 2 :(得分:0)
尝试我的代码,您的问题很容易解决。
[value]="todo.title"