我已经设置了以下设置以在使用 iPad 时选择图像。问题是委托(delegate)似乎永远不会被调用。我已经放置了断点,但它们从未被激活。
.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];
}
任何人都可以看到这个问题吗?
谢谢
最佳答案
如果你使用Xcode8运行项目,请检查项目的info.plist,确保有“Privacy Photo library usage”的 key 。
你的代码是对的,可能是info.plist的问题。
关于IOS 10 UIImagePickerController 委托(delegate)未被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39805662/