警告:尝试在已经呈现的<uiviewcontroller:0x7b9cac00 =“”>上显示<uiimagepickercontroller:0x7ca5dc00 =“”>(null)

时间:2015-05-29 11:56:20

标签: ios objective-c iphone uiimagepickercontroller

我在使用iPad时遇到此错误。但iPhone是有效的。请分享解决方案。我的代码如下。

-(void)pickImageFromLibrary
{

    UIImagePickerController *picker10 = [[UIImagePickerController alloc] init];
    picker10.delegate = self;
    picker10.allowsEditing = YES;
    picker10.view.tag=100;


        picker10.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

    [self presentViewController:picker10 animated:YES completion:NULL];


}

2 个答案:

答案 0 :(得分:2)

你应该尝试这个代码!

[self.presentedViewController dismissViewControllerAnimated:NO completion:nil];

答案 1 :(得分:0)

UIImagePickerCopntroller必须在iPad中以popover呈现。看一下iPad的以下代码:

    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];
}
不要忘记为popover添加强大的属性:

@property (nonatomic, strong) UIPopoverController *popOver;

这是解雇它的委托方法:

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

-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker

这是指向更多信息的类引用的链接:Class Refference