如何在 iPad 上关闭 UIImagePickerController
Posted
技术标签:
【中文标题】如何在 iPad 上关闭 UIImagePickerController【英文标题】:How to dismiss UIImagePickerController on iPad 【发布时间】:2015-08-12 14:07:04 【问题描述】:我正在使用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];
当我使用来自画廊类委托的任何照片时,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
从未被调用,我不知道为什么。用户单击取消时如何关闭弹出框?
【问题讨论】:
【参考方案1】:如果imagePickerControllerDidCancel
没有被调用,则意味着您需要实现UIImagePickerControllerDelegate
例子
@interface ImageViewController : UIViewController<UIImagePickerControllerDelegate>
【讨论】:
以上是关于如何在 iPad 上关闭 UIImagePickerController的主要内容,如果未能解决你的问题,请参考以下文章
UIPopoverController 中的 iPad UIImagePicker 仅选择保存的图像(不是来自相册)?