在UIImagepickercontroller导航栏中添加一个后退按钮

时间:2013-12-06 09:39:07

标签: ios objective-c uinavigationcontroller uiimagepickercontroller uipopovercontroller

我有一个UI图像选择器,它显示在UI popoverController中,我需要UIimage选择器导航栏上的后退按钮,所以我可以回到以前的popover。

让我详细解释一下。 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 是我之前的弹出视图的视图控制器。从哪里来。现在我在弹出窗口中回到这个视图,当我点击导航栏中的后退按钮时。

但我没有任何导航栏。请帮忙

1 个答案:

答案 0 :(得分:2)

如果要通过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];
}

希望回答你的问题。