【问题标题】:UIImagePickerController in UIPopoverController is showing as blank white viewUIPopoverController 中的 UIImagePickerController 显示为空白视图
【发布时间】: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


    【解决方案1】:

    您还应该指定 UIImagePickersourceType

    _picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

    更新

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

    _picker = [[UIImagePickerController alloc] init];

    【讨论】:

    • 正如 Apple 在其 documentation 中所说,这是所述属性的默认值,因此我删除了此代码(我之前有它,它没有区别)。
    • 这很有意义,现在我想到了继承等等。
    • 这不是继承的最佳实践示例。
    • 谢谢,解决了。当我有能力时,我会接受你的回答。
    猜你喜欢
    • 2019-02-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-07
    • 1970-01-01
    • 2021-03-28
    • 1970-01-01
    • 2020-01-01
    相关资源
    最近更新 更多