2015-03-13 5 views
32

कुछ त्वरित कोड में समस्या होने के कारण मैंने ओसीआर अनुवाद ऐप के लिए लिखा था। कोड स्निपेट के नीचे है:UIImagePicker के लिए प्रतिनिधि सेट करना त्रुटि

@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 = आत्म लाइन त्रुटि देता है: uiimagepickerdelegate के प्रकार ViewController का मान निर्दिष्ट नहीं कर सकते।

मैं कक्षा परिभाषा प्रतिनिधि निर्धारित किया है, यह नीचे देखा जा सकता है ...

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

सभी और किसी भी मदद के लिए अग्रिम में की सराहना की जाएगी, धन्यवाद।

उत्तर

77

आप अपने व्यू कंट्रोलर वर्ग परिभाषा में UINavigationControllerDelegate के बारे में भूल गए हैं।

छवि पिकर का प्रतिनिधि वस्तु।

घोषणा

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

क्या एक बेवकूफ गलती है! हाहा मैं फिर से भूल नहीं होगा। मदद के लिए आपका बहुत बहुत धन्यवाद! –

+0

इस उत्तर को सही और बंद करें विषय –

+1

आपको बहुत धन्यवाद> मुझे पता है कि मुझे UINAVIGATIONCONTROLLERDELEGATE – coolcool1994

11

आप वर्ग घोषणा करने के लिए UINavigationControllerDelegate जोड़ना होगा।

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


// Some thing here 

} 
+1

तेजी से एक उदाहरण प्रदान करने के लिए धन्यवाद। –

संबंधित मुद्दे