在我的应用程序中,我有一个表格视图控制器,它创建了几个自定义单元格,我已经为其创建了视图控制器 (.xib) 和类。在其中一个单元格中,有一个按钮触发一种方法(在“内部触摸”),该方法假定向用户呈现图像选择器。我已经使用文档中的苹果标准代码来展示媒体选择器,但它似乎不起作用。我尝试将单元格用作创建媒体选择器的委托和视图控制器,以及作为媒体选择器的委托,但它似乎不起作用。我还尝试过隐含创建单元格的 UITableView 的对象,并将其用作委托和视图控制器,这也不起作用。我已经添加了相关方法的代码。关于如何做到这一点的任何建议?
处理“内部修饰”按钮的方法(在自定义单元格类中使用他的方法):
- (IBAction)TakeNewPicture:(id)sender {
[self startCameraControllerFromViewController:self usingDelegate:self];
}
startCameraController... 方法(也在单元的类中):
- (BOOL) startCameraControllerFromViewController: (UIViewController*) controller
usingDelegate: (id <UIImagePickerControllerDelegate,
UINavigationControllerDelegate>) delegate {
if (([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera] == NO)
|| (delegate == nil)
|| (controller == nil))
return NO;
UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
// Displays a control that allows the user to choose picture or
// movie capture, if both are available:
cameraUI.mediaTypes =
[UIImagePickerController availableMediaTypesForSourceType:
UIImagePickerControllerSourceTypeCamera];
// Hides the controls for moving & scaling pictures, or for
// trimming movies. To instead show the controls, use YES.
cameraUI.allowsEditing = YES;
cameraUI.delegate = delegate;
[controller presentModalViewController: cameraUI animated: YES];
//[[[[UIApplication sharedApplication] keyWindow] rootViewController] presentModalViewController:cameraUI animated:YES];
return YES;
}
谢谢你的时间!非常感谢任何支持:](Objective-c 风格的笑脸)