【问题标题】:IOS 10 UIImagePickerController Delegate Not Being CalledIOS 10 UIImagePickerController 委托未被调用
【发布时间】:2017-02-09 20:48:04
【问题描述】:

我已设置以下内容以在使用 iPad 时选择图像。问题是委托似乎永远不会被调用。我已经放置了断点,但它们从未被激活。

.H

@interface HomeViewController : UIViewController <UINavigationControllerDelegate, UIImagePickerControllerDelegate>

.M

- (IBAction)loadImage:(id)sender {

self.imagePickerController = [[UIImagePickerController alloc] init];
self.imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
self.imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
self.imagePickerController.allowsEditing = NO;
self.imagePickerController.delegate = self;

[self presentViewController:self.imagePickerController animated:YES completion:nil];

}

// This method is called when an image has been chosen from the library or taken from the camera.
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{

//You can retrieve the actual UIImage
UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage];
//Or you can get the image url from AssetsLibrary
NSURL *path = [info valueForKey:UIImagePickerControllerReferenceURL];

[picker dismissViewControllerAnimated:YES completion:nil];
}

谁能看到这个问题?

谢谢

【问题讨论】:

  • 我确实复制并粘贴了您在我创建的新示例项目中编写的代码,但它可以工作。我在没有您描述的情况下添加的一件事是 info.plist 隐私照片库的使用。
  • 嗨,检查了 info.plist 并且隐私设置已经存在。真的很奇怪,因为我似乎找不到问题。
  • 它对我来说也很好用
  • 每个人都在使用 iPad 吗?

标签: ios objective-c


【解决方案1】:

如果您使用Xcode8运行项目,请检查项目的info.plist,确保有“隐私照片库使用”的密钥。

您的代码是正确的,可能问题出在 info.plist。

【讨论】:

  • 您好,已经存在,原来是一个错误,因为重新启动 Ipad 后一切正常。
【解决方案2】:

我遇到了类似的问题,结果发现选择器在选择图像后立即被垃圾收集,因此没有调用委托。

我需要确保在展示之前对选择器进行了强烈的引用。

完成后,它工作正常。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多