设置UIImagePicker的委托返回错误

在我为OCR翻译应用程序编写的代码中遇到问题。 代码片段如下:

@IBAction func btnOCR(sender: AnyObject) { var languageAlert = UIAlertController(title: "For Your Information...", message: "The OCR feature currently only supports English & French.", preferredStyle: .Alert) languageAlert.addAction(UIAlertAction(title: "Okay", style: .Default, handler: { action in var image = UIImagePickerController() image.sourceType = UIImagePickerControllerSourceType.Camera image.allowsEditing = false image.delegate = self presentViewController(image, animated: true, completion: nil) })) self.presentViewController(languageAlert, animated: true, completion: nil) } 

image.delegate = self行返回错误:无法将typesviewcontroller的值分配给uiimagepickerdelegate。

我已经在类定义中设置了委托,这可以在下面看到…

 class ViewController: UIViewController, UITextFieldDelegate, UIPickerViewDelegate, UIPickerViewDataSource, UIImagePickerControllerDelegate { } 

所有和任何帮助将不胜感激,在此先感谢。

您在ViewController类defenition中忘记了UINavigationControllerDelegate。

图像select器的委托对象。

宣言

 unowned(unsafe) var delegate: protocol<UIImagePickerControllerDelegate, UINavigationControllerDelegate>? 

您必须将UINavigationControllerDelegate添加到类声明中。

 class ViewController: UIViewController, UITextFieldDelegate, UIPickerViewDelegate, UIPickerViewDataSource, UIImagePickerControllerDelegate, UINavigationControllerDelegate { // Some thing here }