如何在 iPad 上关闭 UIImagePickerController

How to dismiss UIImagePickerController on iPad

我正在使用 UIImagePickerController

UIImagePickerController *picker = [[UIImagePickerController alloc] init];    
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
popover = [[UIPopoverController alloc] initWithContentViewController:picker];
[popover presentPopoverFromRect:CGRectMake(0, 10, 500, 500) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

当我使用图库中的任何照片时 class 委托 didFinishPickingMediaWithInfo 被调用。

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

    NSLog(@"inside Delegate image pick");

    [popover dismissPopoverAnimated:YES];
    [picker dismissViewControllerAnimated:YES completion:NULL];
}

工作正常,但我在使用 imagePickerControllerDidCancel 委托方法时遇到问题。

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {

    NSLog(@"inside Cancel ");

    [popover dismissPopoverAnimated:YES];

    [picker dismissViewControllerAnimated:YES completion:NULL];
}

imagePickerControllerDidCancel 从未被调用过,我也不知道为什么。如何在用户单击取消时关闭弹出框?

如果 imagePickerControllerDidCancel 没有被调用意味着你需要实现 UIImagePickerControllerDelegate

示例

@interface ImageViewController : UIViewController<UIImagePickerControllerDelegate>