【发布时间】:2014-08-16 13:59:09
【问题描述】:
我目前正在编写一个 iOS 应用程序,我想让用户从他们的照片库中选择一张图片。我不希望他们能够拍摄新照片或编辑现有照片,但现在这并不重要。由于这是一个 iPad 应用程序,我必须在弹出视图中显示 UIImagePickerController 视图(或引发异常等)。这是我目前用来实现这一目标的代码:
- (void)viewDidLoad{
[super viewDidLoad];
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]){
_picker = [[UIImagePickerController alloc] initWithRootViewController:self];
_picker.delegate = self;
}else{
[[[UIAlertView alloc] initWithTitle:@"goto fail;" message:nil delegate:nil cancelButtonTitle:@"Okay" otherButtonTitles:nil] show];
}
self.view.backgroundColor = [UIColor purpleColor];
}
- (void)viewDidAppear:(BOOL)animated{
popoverController = [[UIPopoverController alloc] initWithContentViewController:_picker];
[popoverController presentPopoverFromRect:(CGRect){CGPointZero, {1, 1}} inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:animated];
[super viewDidAppear:animated];
}
显然,我希望这会在弹出窗口中显示图像选择器视图。相反,我得到了这个: 此代码在真正的 iPad 上运行,而不是在模拟器中。我从未被提示授予对我的照片的访问权限,并且在 Preferences.app 的隐私设置的照片区域中没有该应用程序的条目。我在 iPad 4(有摄像头)上测试这个,不能在模拟器中测试,因为它目前有问题。我不确定问题出在哪里——这很令人困惑。
【问题讨论】:
标签: ios objective-c ipad uiimagepickercontroller uipopovercontroller