UIImagePickerControllerDelegate

UIImagePickerControllerDelegate

我正在尝试添加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];,我不知道为什么发生这种情况。

最佳答案

之所以收到此警告,是因为您要传入selfUIImagePickerController属性的对象delegate不符合UIImagePickerControllerDelegate UINavigationControllerDelegate协议。这是因为UIImagePickerControllerUINavigationController的子类,该子类已经声明了自己的delegate
delegate上的UIImagePickerController属性定义为:

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

这意味着它正在期待符合这两个协议的任何对象。

您 class 的@interface声明应为...
@interface GobblesViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate>

10-08 04:44