0

I have an app which has a toolbar at the bottom with one of the options as Upload. On clicking on it, a PopOverController occurs which displays the list of photos to choose from.

After choosing a photo, I want to display a view (inside the PopOverController itself)which contains the photo alongwith the button called as Upload. On choosing my photo, currently my PopOverController is not getting dismissed. I have used the following lines of code :

-(IBAction)photolibrarypressed:(id)sender{
    NSLog(@"hi");

    UIImagePickerController *picker= [[UIImagePickerController alloc] init];
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    picker.delegate = self;

    UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:picker];
    self.popoverController = popover;          
    popoverController.delegate = self;
    [popoverController presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];

    imageView = [[UIImageView alloc] initWithFrame:[window bounds]];


    [window addSubview:imageView];
    imageView.hidden = YES;
    [window makeKeyAndVisible];     
}

- (void)imagePickerController:(UIImagePickerController *)picker 
    didFinishPickingImage:(UIImage *)image
              editingInfo:(NSDictionary *)editingInfo
{
    imageView.image = image;    
    NSLog(@"hellow");
    [self dismissModalViewControllerAnimated:YES];

    // need to show the upload image button now
    upload.hidden = NO;
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    [picker dismissModalViewControllerAnimated:YES];
    exit(0);
}

Can Someone help me to sort out the issue ??

Hamed Rajabi Varamini
  • 3,439
  • 3
  • 24
  • 38
kamalbhai
  • 510
  • 2
  • 10
  • 23

1 Answers1

0

Instead of calling

 [self dismissModalViewControllerAnimated:YES];

call the same cancel method as int eh cancel method to handle dismissing it's modal view

 [picker dismissModalViewControllerAnimated:YES]; // Dismisses modalView
flashfabrixx
  • 1,183
  • 9
  • 22
  • I dont want to dismiss the PopOver .. It should still exist .. I want to dismiss the ModalViewController which is displaying my selected image. I am getting two options of `Use` and `Cancel` .. On clicking on cancel, the `ModlViewController` gets dismissed but on clicking on `Use` it does not happen. I am unable to get it .. – kamalbhai Jul 17 '12 at 09:59
  • And it doesn't work if you just use the same method as in the cancel method (calling picker instead of self)? [Updated code above] – flashfabrixx Jul 17 '12 at 10:02
  • for `cancel` method, both (`self` as well as `picker`) are working. but, in the other function, none is working. – kamalbhai Jul 17 '12 at 10:05
  • Couldn't find the problem at the moment. At least try calling [self.parentViewController dismissModalViewControllerAnimated:YES]; and see if it works. – flashfabrixx Jul 17 '12 at 10:16
  • Okay, so use Xcodes terminal, type in `po [[self view] recursiveDescription]` to check your view hierarchy and check if your displayed view with the selected image is somehow added to the wrong view. In [this thread](http://stackoverflow.com/questions/1247992/after-displaying-and-dismissing-the-modal-view-controller-uiimagepickercontrolle) they are calling `[picker.view removeFromSuperview];` as well to get to the point. – flashfabrixx Jul 17 '12 at 10:51