- (void) navigationController: (UINavigationController *) navigationController willShowViewController: (UIViewController *) viewController animated: (BOOL) animated {
if (imagePickerController.sourceType == UIImagePickerControllerSourceTypePhotoLibrary) {
UIBarButtonItem* button = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:@selector(showCamera:)];
viewController.navigationItem.rightBarButtonItems = [NSArray arrayWithObject:button];
} else {
UIBarButtonItem* button = [[UIBarButtonItem alloc] initWithTitle:@"Library" style:UIBarButtonItemStylePlain target:self action:@selector(showLibrary:)];
viewController.navigationItem.leftBarButtonItems = [NSArray arrayWithObject:button];
viewController.navigationItem.title = @"Take Photo";
viewController.navigationController.navigationBarHidden = NO; // important
}
}
- (void) showCamera: (id) sender {
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
}
- (void) showLibrary: (id) sender {
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
}