In my app, I have a table view controller that creates a couple of customize cells, which I have created view controllers (.xib) and classes for. In one of those cells, there is a button that triggers a method (at ‘touch up inside’) that is suppose to present the user with an image picker. I have used apple standard code from the documentation for presenting the media picker, but it doesn’t seem to work. I have tried using the cell as both the delegate and view controller which the media picker is created from, and as the delegate for the media picker, but it doesn’t seem to work. I have also tried Insiniciating an object of the UITableView the cell is created in, and using it as the delegate and view controller, which also doesn’t work. I have added the code for the related methods. Any advice on how to do that?
The method to handle buttons ‘touch up inside” (method his in the custom cell class):
- (IBAction)TakeNewPicture:(id)sender {
[self startCameraControllerFromViewController:self usingDelegate:self];
}
The startCameraController… method (also in the cell’s class):
- (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;
}
Thanks for your time! Any support is highly appreciated :] (Objective-c style smiley)
First I hope u r not running this in the simulator, because as u know it doesn’t have a camera:)
You say that
TakeNewPictureis in the custom cell class, and inside it you call[self startCameraControllerFromViewController:self usingDelegate:self];Were self is a custom cell not a UIViewController..
I would suggest to move this code to the viewController and when u create a cell just do