从不兼容类型'CameraVIewController *''</uinavigationcontrollerdelegate,uiimagepickercontrollerdelegate>分配给'id <uinavigationcontrollerdelegate,uiimagepickercontrollerdelegate>'

时间:2011-12-20 06:55:34

标签: objective-c ipad

Assigning to id<UINavigationControllerDelegate,UIImagePickerControllerDelegate> from incompatible type CameraViewController*警告显示在picker.delegate = self;行附近

-(IBAction) getPhoto:(id) sender {
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;

if((UIButton *) sender == takePhoto) {
    picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
} else {
    //picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
   picker.sourceType = UIImagePickerControllerSourceTypeCamera;
}

[self presentModalViewController:picker animated:YES];

}

3 个答案:

答案 0 :(得分:83)

请注意,您必须同时遵守UIImagePickerControllerDelegateUINavigationControllerDelegate协议才能使用图片选择器。

答案 1 :(得分:14)

只需添加两种协议。

@interface MyViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate>

然后显然设置委托。 :)

答案 2 :(得分:8)

The documentation for UIImagePickerController表示委托必须实施UIImagePickerControllerDelegate协议。您的CameraViewController要么没有实现此协议,要么没有声明它在标题中这样做。