RomanHouse
RomanHouse

Reputation: 2552

Get image from gallery with UIPopover and show it

I'm trying to get image from gallery and than display it in UIImageView. My problem is in displaying this image. My code:

- (void)getMediaFromSource:(UIImagePickerControllerSourceType)sourceType {

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

     self.popController = [[UIPopoverController alloc] initWithContentViewController:imagePickerController];
     self.popController.delegate = self;
     [self.popController presentPopoverFromRect:[fromGalaryButton frame] inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
     [self.popController dismissPopoverAnimated:YES];
     self.image = [info objectForKey:UIImagePickerControllerEditedImage];
     [self updateDisplay];
 }

 -(void)updateDisplay {
     self.imageView.image = self.image;
     self.imageView.hidden = NO;
     [self.imageView reloadInputViews];
}

My self.imageView is displaying normally. But there is no any image in. There is my problem?

Upvotes: 0

Views: 289

Answers (1)

Siddharth Dhingra
Siddharth Dhingra

Reputation: 456

If you are just picking in image from the gallery then the line of code in didFinishPickingMediaWithInfo method should be:

self.image = [info objectForKey:UIImagePickerControllerOriginalImage];

You could also just update the imageView from within the method as such:

self.imageView.image = [info objectForKey:UIImagePickerControllerOriginalImage];

This is how I did this:

- (void)viewDidLoad {
  [super viewDidLoad];
  picker = [[UIImagePickerController alloc] init];
  picker.delegate = self;
  imagePickerPopover = [[UIPopoverController alloc] initWithContentViewController:picker];

}

- (IBAction)getPhoto:(id)sender {

if(sender == choosePhotoButton) {
   picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
   [imagePickerPopover presentPopoverFromBarButtonItem:choosePhotoButton permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
}

    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
        [imagePickerPopover dismissPopoverAnimated:YES];
        imageViewer.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

    }

Upvotes: 2

Related Questions