我有两个类:View1和SelectImage。 View1导入SelectImage。 SelectImage用于向用户呈现UIView,允许他们选择如何从设备中获取照片。点击该列表中的按钮然后向以下方法之一发送消息...
在此代码中:
-(void)importFromCamera:(id)sender
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
[imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
[imagePicker setDelegate:self];
[self presentModalViewController:imagePicker animated:YES];
}
-(void)importFromPhotoLibrary:(id)sender
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
[imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
[imagePicker setDelegate:self];
[self presentModalViewController:imagePicker animated:YES];
}
-(void)importFromSavedPhotosAlbum:(id)sender
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
[imagePicker setSourceType:UIImagePickerControllerSourceTypeSavedPhotosAlbum];
UIViewController *viewController = [UIViewController alloc];
[imagePicker setDelegate:self];
[self presentModalViewController:imagePicker animated:YES];
}
编译器抱怨:
实例消息的接收者类型“SelectImage”未声明a 选择器'presentModalViewController:animated:'
的方法
在[self presentModalViewController:imagePicker animated:YES]的每个实例中;
不确定我缺少什么。我环顾四周,只能找到将所有内容保存在一个班级中的例子。
是因为该类是UIView而不是UIViewController?我很确定我已经制定了必要的委托协议:。
我正在尝试将此功能保留在类中,以允许其他视图也使用它(View2,View3等)。
谢谢!
答案 0 :(得分:0)
是。 presentModalViewController是UIViewController
而非UIView
请注意,在iOS 5上,首选使用的方法是:
- (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion
SelectImage
类可以拥有UIViewController
实现的委托。 SelectImage类上的按钮的操作方法将调用您的委托(即UIViewController)。
答案 1 :(得分:0)
SelectImage应该是一个UIViewController。称之为SelectImageController,然后view1可以添加它的视图,如[view1 addSubview:self.selectImageController.view];