So I have a UINavigationController that pushes a UITableViewController from the rootViewController. From the UITableViewController, I want a UIImagePickerController to be pushed when I click a certain cell. How would I get the navigation controller to display the image picker?
1 Answer
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
[self presentModalViewController:imagePicker animated:YES];
// don't release imagePicker here
}
Then define UIPickerControllerDelegate in your tableViewController implementation.
2 Comments
shezi
Note that the first will not work, because UIImagePickerController is itself a UINavigationController and cannot be embedded in another navigation controller. Also, neither of these will work on the iPad. As per the documentation you can only show a UIImagePickerController in a UIPopoverController or as a replacement of the current view.
eladleb
I think the first should be removed, as it will cause an exception like shezi states, and that can be confusing to users reading this answer.