我有一个UI图像选择器,它显示在UI popoverController中,我需要在UIimage选择器导航栏上单击一个后退按钮,以便可以返回上一个弹出窗口。
让我详细解释。
1)我有一个弹出窗口,在其中我点击并发出通知,在我希望此摄像机图像选择器弹出的视图控制器上读取此通知。以下是我的代码
-(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是我以前的弹出视图的视图控制器。我来自哪里现在,当我点击导航栏中的“后退”按钮时,我想回到弹出窗口中的该视图。
但我没有任何导航栏。请帮助
最佳答案
如果要通过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/