Illep
Illep

Reputation: 16849

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.

Upvotes: 3

Views: 2013

Answers (1)

Mark Adams
Mark Adams

Reputation: 30846

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>

Upvotes: 10

Related Questions