添加UIImagePickerController时发出警告

时间:2012-01-10 16:45:15

标签: iphone objective-c ios cocoa-touch

我正在尝试添加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;

compiler warning

[imagePicker setDelegate:self];的警告点,我不知道为什么会发生这种情况。

1 个答案:

答案 0 :(得分:10)

您收到此警告是因为在这种情况下,您传递给self的{​​{1}}属性的对象UIImagePickerController不符合{ {1}} delegate协议。这是因为UIImagePickerControllerDelegateUINavigationControllerDelegate的子类,它已经声明了它自己的UIImagePickerController

UINavigationController上的delegate属性定义为:

delegate

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

您班级的UIImagePickerController声明应该是......

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