我正在尝试添加UIImagePickerController
,并且收到incompatible type 'id<UINavigationControllerDelegate,UIImagePickerControllerDelegate>'
编译器警告。我要知道为什么吗及其解决方案。
.m
imagePicker = [[UIImagePickerController alloc] init];
[imagePicker setDelegate:self];
。H
@interface GobblesViewController : UIViewController <UIImagePickerControllerDelegate>
{
UIImagePickerController *imagePicker;
}
@property (nonatomic,strong)UIImagePickerController *imagePicker;
警告指向
[imagePicker setDelegate:self];
,我不知道为什么发生这种情况。 最佳答案
之所以收到此警告,是因为您要传入self
的UIImagePickerController
属性的对象delegate
不符合UIImagePickerControllerDelegate
和 UINavigationControllerDelegate
协议。这是因为UIImagePickerController
是UINavigationController
的子类,该子类已经声明了自己的delegate
。delegate
上的UIImagePickerController
属性定义为:
@property (nonatomic, assign) id <UINavigationControllerDelegate, UIImagePickerControllerDelegate> delegate;
这意味着它正在期待符合这两个协议的任何对象。
您 class 的
@interface
声明应为...@interface GobblesViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate>