崩溃;隐私已添加到 info.plist
let myPickerController = UIImagePickerController()
myPickerController.delegate = self
myPickerController.sourceType = .photoLibrary
self.present(myPickerController, animated: true, completion: nil)'
错误:
无法识别的选择器已发送到实例0x28184fb40 2019-09-09 12:45:52.126598 + 0300 ***由于未捕获的异常而终止应用程序 'NSInvalidArgumentException',原因:'-[__ NSCFType encodeWithCoder:]: 无法识别的选择器已发送到实例0x28184fb40'
答案 0 :(得分:0)
尝试一下:
let imagePicker = UIImagePickerController()
imagePicker.delegate = self
let cameraAction = UIAlertController(title: "Title", message: "Choose to upload a picture", preferredStyle: .alert)
cameraAction.addAction(UIAlertAction(title: "Camera", style: .default, handler: {(action) in
imagePicker.sourceType = UIImagePickerController.SourceType.camera
self.present(imagePicker, animated: true){
}
}))
cameraAction.addAction(UIAlertAction(title: "Photo Library", style: .default, handler: {(action) in
imagePicker.sourceType = .photoLibrary
self.present(imagePicker, animated: true){
}
}))
imagePicker.allowsEditing = true
self.present(cameraAction, animated: true)
答案 1 :(得分:0)
我假设您点击一个按钮以启动UIImagePickerController
。我怀疑如果您是使用界面生成器设计的,则可能会将您的按钮连接到多个IBAction
方法上。
转到情节提要,然后右键单击按钮。如果按钮连接到多个“已发送事件”,那就是您的问题。删除不相关的内容(也许您在代码中删除的旧内容仍处于连接状态)。