Domanda

i have a UI Image picker and its being shown inside a UI popoverController, i need a back button on UIimage picker navbar, so i can go back to previous popover.

let me explain in details. 1) i have a popup in which i tap and raise a notification, this notification is read on a view controller where i want this camera image picker popup. following is my code

-(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 is UI Image picker

applicationDiscriptionPopupViewControllerObj is view controller of my previous popover view. from where i came. now i wana go back to this view in the popup, when i tap on back button in nav bar.

but i dnt hav any nav bar. plz help

È stato utile?

Soluzione

If you are adding a UIImagePickerController via presentViewController inside a UIViewController then you should see the default navigation bar.
  You should implement :

- (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;
}

Add a back button action handler

-(void)backAction{
    [self.navigationController popViewControllerAnimated:YES];
}

Hope that answer ur Q.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top