Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WARNING when adding UIImagePickerController

I am trying to add an UIImagePickerController and i get an incompatible type 'id<UINavigationControllerDelegate,UIImagePickerControllerDelegate>' compiler warning. I need to know why? and a solution for it.

.m

imagePicker = [[UIImagePickerController alloc] init];
[imagePicker setDelegate:self];

.h

@interface GobblesViewController : UIViewController <UIImagePickerControllerDelegate>
{
  UIImagePickerController *imagePicker;
}
@property (nonatomic,strong)UIImagePickerController *imagePicker;

compiler warning

The warning point to [imagePicker setDelegate:self]; and i have no clue why this is occurring.

like image 930
Illep Avatar asked Mar 20 '26 03:03

Illep


1 Answers

You're getting this warning because the object, self in this case, that you're passing in to UIImagePickerController's delegate property, doesn't conform to the UIImagePickerControllerDelegate and UINavigationControllerDelegate protocols. This is because UIImagePickerController is a subclass of UINavigationController which already declares it's own delegate.

The delegate property on UIImagePickerController is defined as:

@property (nonatomic, assign) id <UINavigationControllerDelegate, UIImagePickerControllerDelegate> delegate;

Which means it is anticipating any object that conforms to those two protocols.

The @interface declaration for your class should be...

@interface GobblesViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate>
like image 125
Mark Adams Avatar answered Mar 21 '26 16:03

Mark Adams