0

I have an application that allows the user to select a photo from their camera roll, and display it in a UIImageView. But, after they tap on which image they would like to display, the camera roll's view does not disappear. So, I figured that I would need to simply call [sender resignFirstResponder];. But, this did not do the trick. I've been trying multiple things and doing searching around, but to no avail. I'm very new to Objective-C, so any help is much appreciated. Here is the code I'm working with: (imgPicker is the UIImagePickerController.)

 - (IBAction)grabImage(id)sender {
        self.imgPicker = [[UIImagePickerController alloc] init];
        self.imgPicker.delegate = self;
        self.imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
            _popover = [[UIPopoverController alloc] initWithContentViewController:imgPicker];
            [_popover presentPopoverFromRect:self.imageView.bounds inView:self.imageView permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
        } 

        else {
            [self presentModalViewController:imgPicker animated:YES];
        }
        [self.imgPicker resignFirstResponder];
    }

And this may or may not be relevant to the issue:

    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)editInfo {
        if (imageView.image == nil) {
            imageView.image = img;
            [[picker parentViewController] dismissModalViewControllerAnimated:YES];
            return;

        }

        if (imageView2.image == nil) {
            imageView2.image = img;
            [[picker parentViewController] dismissModalViewControllerAnimated:YES];
            return;
        }
    }
Henry F
  • 4,960
  • 11
  • 55
  • 98

3 Answers3

1

You need just this line to dismiss modal picker in your delegate method:

[picker dismissModalViewControllerAnimated:YES];

resignFirstResponder in this case is useless

beryllium
  • 29,669
  • 15
  • 106
  • 125
1

Try

[self dismissModalViewControllerAnimated:YES];
Legolas
  • 12,145
  • 12
  • 79
  • 132
0

As you want to dismiss only picker view and not parent view of picker

you just have to use:

[picker dismissModalViewControllerAnimated:YES];

and you are done.

pjumble
  • 16,880
  • 6
  • 43
  • 51
Yuvrajsinh
  • 4,536
  • 1
  • 18
  • 32