25

Assigning to id<UINavigationControllerDelegate,UIImagePickerControllerDelegate> from incompatible type CameraViewController* warning shows near picker.delegate = self; line

-(IBAction) getPhoto:(id) sender {
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;

if((UIButton *) sender == takePhoto) {
    picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
} else {
    //picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
   picker.sourceType = UIImagePickerControllerSourceTypeCamera;
}

[self presentModalViewController:picker animated:YES];

}

Jim
  • 72,985
  • 14
  • 101
  • 108
susitha
  • 467
  • 3
  • 9
  • 16
  • [This][1] is the best answer that I founded for this question. [1]: http://stackoverflow.com/questions/4727895/iphone-uiimagepickercontrollerdelegate-inheritance – Josip B. Jul 11 '12 at 16:16
  • 2
    Now I noticed that you need to also assign your UIViewController to UINavigationControllerDelegate protocol, because documentation says this for UIImagePickerControllerDelegate: @property(nonatomic,assign) id delegate; so it means you need to assign to both of these protocols. – Josip B. Jan 03 '13 at 16:09

3 Answers3

83

Note that you must conform to both the UIImagePickerControllerDelegate and UINavigationControllerDelegate protocols to use the image picker.

Kyle Clegg
  • 38,547
  • 26
  • 130
  • 141
  • 2
    This one did it for me. Thanks! – Mike Apr 11 '14 at 20:48
  • 3
    This should be marked correct - Most people expect that UIImagePickerControllerDelegate is required, but overlook that it's asking for UINavigationControllerDelegate as well. Thanks for your answer. – Adama Oct 10 '14 at 17:44
  • 2
    Why on earth does it need UINavigationControllerDelegate? That's a real mystery. – fatuhoku Feb 13 '15 at 23:48
14

Just add both protocols.

@interface MyViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate>

Then set the delegate obviously. :)

emotality
  • 12,795
  • 4
  • 39
  • 60
7

The documentation for UIImagePickerController says that the delegate must implement the UIImagePickerControllerDelegate protocol. Your CameraViewController either doesn't implement this protocol, or doesn't declare that it does so in its header.

Jim
  • 72,985
  • 14
  • 101
  • 108