UIImagePickerController未出现在iPad发行版中

UIImagePickerController未出现在iPad发行版中,ipad,ios-simulator,uiimagepickercontroller,Ipad,Ios Simulator,Uiimagepickercontroller,我正在尝试演示UIImagepickerController以打开图像库。它在iPhone中工作正常,但在iPad应用程序中崩溃,出现以下错误“受支持的方向与应用程序没有共同的方向,并且shouldAutorotate返回YES”” p.S:我的应用程序仅在iPhone中支持肖像。在iPad上,UIImagePickerController必须通过UIPopoverController呈现。对于iPad,您应该在UIPopoverController中呈现,而不是使用直接呈现。这应该可以解决这个

我正在尝试演示UIImagepickerController以打开图像库。它在iPhone中工作正常,但在iPad应用程序中崩溃,出现以下错误“受支持的方向与应用程序没有共同的方向,并且shouldAutorotate返回YES”

p.S:我的应用程序仅在iPhone中支持肖像。在iPad上,UIImagePickerController必须通过UIPopoverController呈现。对于iPad,您应该在UIPopoverController中呈现,而不是使用直接呈现。这应该可以解决这个问题

为UIPopoverController添加强属性

@property (nonatomic, strong) UIPopoverController *popOver;
应在委托方法中取消popover:

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info 

-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker 
然后在.m文件中编写以下代码

if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:picker];
[popover presentPopoverFromRect:self.selectedImageView.bounds inView:self.selectedImageView permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
self.popOver = popover;
} else {
[self presentModalViewController:picker animated:YES];
}