从不兼容类型'CameraVIewController *''分配给'id '

时间:2022-08-23 04:15:22

Assigning to id<UINavigationControllerDelegate,UIImagePickerControllerDelegate> from incompatible type CameraViewController* warning shows near picker.delegate = self; line

从不兼容类型CameraViewController *警告中分配id 显示在picker.delegate = self附近;线 ,uiimagepickercontrollerdelegate>

-(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 个解决方案

#1


7  

The documentation for UIImagePickerController says that the delegate must implement the UIImagePickerControllerDelegate protocol. Your CameraViewController either doesn't implement this protocol, or doesn't declare that it does so in its header.

UIImagePickerController的文档说该委托必须实现UIImagePickerControllerDelegate协议。您的CameraViewController要么没有实现此协议,要么没有声明它在其标头中这样做。

#2


82  

Note that you must conform to both the UIImagePickerControllerDelegate and UINavigationControllerDelegate protocols to use the image picker.

请注意,您必须符合UIImagePickerControllerDelegate和UINavigationControllerDelegate协议才能使用图像选择器。

#3


13  

Just add both protocols.

只需添加两个协议。

@interface MyViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate>

Then set the delegate obviously. :)

然后显然设置委托。 :)

#1


7  

The documentation for UIImagePickerController says that the delegate must implement the UIImagePickerControllerDelegate protocol. Your CameraViewController either doesn't implement this protocol, or doesn't declare that it does so in its header.

UIImagePickerController的文档说该委托必须实现UIImagePickerControllerDelegate协议。您的CameraViewController要么没有实现此协议,要么没有声明它在其标头中这样做。

#2


82  

Note that you must conform to both the UIImagePickerControllerDelegate and UINavigationControllerDelegate protocols to use the image picker.

请注意,您必须符合UIImagePickerControllerDelegate和UINavigationControllerDelegate协议才能使用图像选择器。

#3


13  

Just add both protocols.

只需添加两个协议。

@interface MyViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate>

Then set the delegate obviously. :)

然后显然设置委托。 :)