UIPopoverController中的UIImagePickerController显示为空白视图

时间:2014-06-25 20:48:28

标签: ios objective-c ipad uiimagepickercontroller uipopovercontroller

我正在编写一个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];
}

我希望这可以在popover中显示图像选择器视图。相反,我明白了: 此代码在真正的iPad上运行,而不是在模拟器中运行。我从未被提示授予对我的照片的访问权限,并且在Preferences.app的隐私设置的照片区域中没有该应用的条目。我正在iPad 4(它有一个摄像头)上测试它,并且无法在模拟器中测试,因为它目前有问题。我不确定问题可能来自哪里 - 这非常令人困惑。

1 个答案:

答案 0 :(得分:2)

此外,您应指定 UIImagePicker sourceType

_picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

<强>更新

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

_picker = [[UIImagePickerController alloc] init];