我有一个具有以下结构的 ViewController 类:
头文件:
@protocol GCStageViewControllerDelegate;
@interface GCStageViewController : UIViewController <UIActionSheetDelegate, UITextFieldDelegate, UIImagePickerControllerDelegate> {
id <GCStageViewControllerDelegate> delegate;
...
}
@property (nonatomic, retain) id <GCStageViewControllerDelegate> delegate;
...
@end
@protocol GCStageViewControllerDelegate
- (void)gcStageViewContollerDidFinish:(GCStageViewController *)controller withGCStageItem:(GCStageItem *)item;
@end
实现文件:
- (void)viewDidLoad {
...
stageInputTextField.delegate = self; // works
...
}
- (void)takePicture {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
[imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
} else {
[imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
}
imagePicker.delegate = self; // here I get the error
[self presentModalViewController:imagePicker animated:YES];
}
如果我在 takePicture 方法中设置委托,我会收到以下警告:
分配给
'id<UINavigationControllerDelegate,UIImagePickerControllerDelegate>'
不兼容的类型'GCStageViewController *'
有什么想法有什么问题吗?