我在Swift编码方面很新,而且我对相机和库的使用有问题。我有这部分代码:
@IBAction func camera(_ sender: Any) {
if !UIImagePickerController.isSourceTypeAvailable(.camera) {
return
}
let cameraPicker = UIImagePickerController()
cameraPicker.delegate = self
cameraPicker.sourceType = .camera
cameraPicker.allowsEditing = false
present(cameraPicker, animated: true)
}
@IBAction func openLibrary(_ sender: Any) {
let picker = UIImagePickerController()
picker.allowsEditing = false
picker.delegate = self
picker.sourceType = .photoLibrary
present(picker, animated: true)
}
}
在cameraPicker.delegate=self和picker.delegate=self中,会抛出如下错误:
无法将“ViewController”类型的值赋给类型(UIImagePickerControllerDelegate和UINavigationControllerDelegate)
我真的不知道怎么解决这个问题。如果有人能帮我做这个我会很感激的,提前谢谢你!
最佳答案
你只需要像
class ViewConroller: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {
...
}