OGeek|极客世界-中国程序员成长平台

标题: ios - UIPopoverController 中的 UIImagePickerController 显示为空白 View [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 10:37
标题: ios - UIPopoverController 中的 UIImagePickerController 显示为空白 View

我目前正在编写一个 iOS 应用程序,我想让用户从他们的照片库中选择一张图片。我不希望他们能够拍摄新照片或编辑现有照片,但现在这并不重要。由于这是一个 iPad 应用程序,我必须在弹出 View 中显示 UIImagePickerController View (或引发异常等)。这是我目前用来实现这一目标的代码:

- (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)viewDidAppearBOOL)animated{
    popoverController = [[UIPopoverController alloc] initWithContentViewController:_picker];
    [popoverController presentPopoverFromRectCGRect){CGPointZero, {1, 1}} inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:animated];
    [super viewDidAppear:animated];
}

显然,我希望这会在弹出窗口中显示图像选择器 View 。相反,我得到了这个: 此代码在真正的 iPad 上运行,而不是在模拟器中。我从未被提示授予对我的照片的访问权限,并且在 Preferences.app 的隐私设置的照片区域中没有该应用程序的条目。我正在 iPad 4(有摄像头)上对此进行测试,并且无法在模拟器中进行测试,因为它目前存在问题。我不确定问题出在哪里——这很令人困惑。



Best Answer-推荐答案


您还应该指定 UIImagePickersourceType

_picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

更新

以这种方式初始化选择器:

_picker = [[UIImagePickerController alloc] init];

关于ios - UIPopoverController 中的 UIImagePickerController 显示为空白 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24418263/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4