我有一个 UI 图像选择器,它显示在 UI popoverController 中,我需要在 UIimage picker 导航栏上有一个后退按钮,这样我就可以返回到上一个弹出框。
让我详细解释一下。 1)我有一个弹出窗口,我在其中点击并发出通知,这个通知是在我想要这个相机图像选择器弹出窗口的 View Controller 上读取的。以下是我的代码
-(void)registerNotificationForCameraSource
{
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(mediaSourceCallback:) name:NOTIFICATION_FOR_CAMERA_SOURCE object:nil];
}
#pragma mark - Image picker Popover
-(void)mediaSourceCallback:(NSNotification *)notificationObj
{
capturedImages = [[NSMutableArray alloc] init];
pickerObj = [[UIImagePickerController alloc] init];
// [pickerObj setContentSizeForViewInPopover:CGSizeMake(320,480)];
pickerObj.delegate = self;
if ([notificationObj.object isEqualToString:@"UIImagePickerControllerSourceTypeCamera"])
{
pickerObj.sourceType = UIImagePickerControllerSourceTypeCamera;
pickerObj.modalPresentationStyle = UIModalPresentationFullScreen;
pickerObj.showsCameraControls = YES;
[self presentViewController:pickerObj animated:YES completion:nil];
}
else
{
[[UINavigationBar appearanceWhenContainedIn:[ApplicationDiscriptionPopupViewController class], nil] setBarTintColor:[UIColor redColor]];
pickerObj.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"Back" style:UIBarButtonItemStyleDone target:self action:@selector(imagePickerBackButtonTapped)];
[pickerObj.navigationController.navigationBar setBarTintColor:[UIColor redColor]];
[pickerObj setNavigationBarHidden:NO animated:YES];
//navigationControllerObj = [[UINavigationController alloc] initWithRootViewController:applicationDiscriptionPopupViewControllerObj];
_popoverControllerObj.popoverContentSize = CGSizeMake(320,480);
pickerObj.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[pickerObj presentedViewController];
[_popoverControllerObj setContentViewController:pickerObj animated:YES];
}
}
-(void)imagePickerBackButtonTapped
{
[pickerObj popToViewController:applicationDiscriptionPopupViewControllerObj animated:YES]; }
pickerObj 是 UI 图像选择器
applicationDiscriptionPopupViewControllerObj 是我之前的弹出 View 的 View Controller 。从我来的地方。现在我想在弹出窗口中返回到这个 View ,当我点击导航栏中的后退按钮时。
但我没有任何导航栏。请帮忙
最佳答案
如果您在 UIViewController 中通过 presentViewController 添加 UIImagePickerController,那么您应该会看到默认导航栏。
你应该实现:
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
UINavigationItem *navBarTopItem;
// you cannot add a custom back button with native back button look like, so use image over
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back_arrow.png"]
style:UIBarButtonItemStyleBordered
target:self
action:@selector(backAction)];
navBarTopItem.title = @"Albums"; // "Camera
navBarTopItem.leftBarButtonItem = backButton;
}
添加后退按钮操作处理程序
-(void)backAction{
[self.navigationController popViewControllerAnimated:YES];
}
希望能回答你的问题。
关于ios - 向 UIImagepickercontroller 导航栏添加后退按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20420569/