• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - UIPopoverController 中的 UIImagePickerController 显示为空白 View

[复制链接]
菜鸟教程小白 发表于 2022-12-12 10:37:01 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

我目前正在编写一个 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/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap