UIImagePickerController委托警告

时间:2012-03-02 09:56:50

标签: delegates warnings uiimagepickercontroller

我刚刚在我的项目中放了一个照片选择器,一切正常。唯一的事情就是它坚持在我设置代表的地方给我以下警告 -

Assigning to 'id<UINavigationControllerDelegate,UIImagePickerDelegate>' from incompatible type 'AddTargetViewController *'

我已经以正常方式在AddTargetViewController.h中设置了委托 -

@interface AddTargetViewController : UIViewController <UIImagePickerControllerDelegate>

我看不出有什么不对。正如我所说,它工作正常,并且所有委托方法都应该按照它们的方式启动。

-(void)takePhoto {

    UIImagePickerController *imagePicker = [[[UIImagePickerController alloc] init] autorelease];

    imagePicker.delegate = self; // *** warning on this line ***
    imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
    imagePicker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;

    [self presentModalViewController:imagePicker animated:YES];

}

感谢您的帮助!

2 个答案:

答案 0 :(得分:36)

这是iPhone - UIImagePickerControllerDelegate inheritance的重复问题。

简而言之,除了UINavigationControllerDelegate之外,您的视图控制器必须符合UIImagePickerDelegate

答案 1 :(得分:3)

您的UIImagePickerControllerDelegate只需在.h文件中添加UINavigationControllerDelegate,它就可以正常使用。