Ios UIPopoverController中的UIImagePickerController显示为空白白色视图

Ios UIPopoverController中的UIImagePickerController显示为空白白色视图,ios,objective-c,ipad,uiimagepickercontroller,uipopovercontroller,Ios,Objective C,Ipad,Uiimagepickercontroller,Uipopovercontroller,我目前正在编写一个iOS应用程序,我想让用户从他们的照片库中选择一幅图像。我不希望他们能够拍摄新照片或编辑现有的照片,但现在这并不重要。由于这是一个iPad应用程序,我必须在popover视图中显示UIImagePickerController视图(或者引发异常,等等)。这是我目前试图实现的代码: - (void)viewDidLoad{ [super viewDidLoad]; if([UIImagePickerController isSourceTypeAvailable:

我目前正在编写一个iOS应用程序,我想让用户从他们的照片库中选择一幅图像。我不希望他们能够拍摄新照片或编辑现有的照片,但现在这并不重要。由于这是一个iPad应用程序,我必须在popover视图中显示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隐私设置的照片区域中没有该应用的条目。我正在iPad4(有摄像头)上测试,但无法在模拟器上测试,因为它目前有问题。我真的不确定问题来自何处-这相当令人困惑。

您还应该指定UIImagePicker源类型

_picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
更新

按以下方式初始化选择器:

_picker = [[UIImagePickerController alloc] init];

正如苹果在其声明中所说,这是上述属性的默认值,所以我删除了这段代码(我以前在那里有过它,它没有什么区别)。现在我考虑到继承和所有内容,这很有意义。这不是继承的最佳实践示例。谢谢,这修复了它。当我有能力的时候,我会接受你的回答。