UIPopoverController和崩溃的UIImagePickerController(UIP

2019-09-29 00:10发布

这是我的观点的建立:

UIBarButtonItem被点击,就应该调出UIImagePickerController 。 我必须这样做使用UIPopoverController ,这是通过点击“重置”按钮调用,因为需要在iPad上。 这里是我的代码:

-(IBAction) btnReset:(id)sender {
    [self chooseImage];
}

-(void) chooseImage {
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
        imagepicker = [[UIImagePickerController alloc] init];
        imagepicker.allowsEditing = NO;
        imagepicker.delegate = self;
        imagepicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        imagepicker.navigationBar.opaque = true;


        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
            popoverController = [[UIPopoverController alloc] initWithContentViewController:imagepicker];

            [popoverController presentPopoverFromBarButtonItem:reset permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];

        } else {
            [self presentModalViewController:imagepicker animated:YES];   
        }
    }
}

但是,如果这就是所谓的观点崩溃与错误:

“NSInvalidArgumentException”的,原因是:“ - [UIPopoverController presentPopoverFromRect:inView:permittedArrowDirections:动画:]:Popovers不能由不具有窗口的图呈现”

我究竟做错了什么? 先感谢您。

Answer 1:

它看起来像你想的是不是对视图层次的项目创建酥料饼。 如果这个方法是由您的按钮调用然后更改方法头 - (空)chooseImage:(ID)发送,并尝试从你有你的工具栏上的UIBarButton呈现酥料饼。

此外,如果你正在使用ARC(它看起来像你),你必须坚持自己的UIPopover否则,当仍然需要它看到它会被释放这个堆栈溢出职位 。 您可能已经这样做,但我想我会提高它作为一个如果/你是如何规定的popoverController我看不到。



文章来源: UIPopoverController and UIImagePickerController crash