UIPopoverController和UIImagePickerController崩溃 [英] UIPopoverController and UIImagePickerController crash

查看:194
本文介绍了UIPopoverController和UIImagePickerController崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我的观点设置:

点击 UIBarButtonItem 后,它会显示的UIImagePickerController 。我必须使用 UIPopoverController 来执行此操作,这是通过单击重置按钮调用的,因为它在iPad上是必需的。这是我的代码:

When the UIBarButtonItem is clicked, it should bring up a UIImagePickerController. I have to do this using a UIPopoverController, which is invoked by clicking on the "reset" button, because it is necessary on the iPad. Here is my code:

-(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];   
        }
    }
}

然而,当这个被调用时,视图崩溃并出现错误:

However, when this is called, the view crashes with the error:


'NSInvalidArgumentException',原因:' - [UIPopoverController presentPopoverFromRect:inView:allowedArrowDirections:animated:]:弹出窗口不能从没有窗口的视图中显示。'

'NSInvalidArgumentException', reason: '-[UIPopoverController presentPopoverFromRect:inView:permittedArrowDirections:animated:]: Popovers cannot be presented from a view which does not have a window.'

我做错了什么?提前谢谢你。

What am I doing wrong? Thank you in advance.

推荐答案

看起来你正试图在一个不在视图层次结构上的项目上创建一个弹出窗口。如果您的按钮调用此方法,则将方法标题更改为 - (void)chooseImage:(id)sender并尝试使用工具栏上的UIBarButton显示弹出框。

It looks like you are trying to create a popover on an item which is not on the view hierarchy. If this method is being invoked by your button then change the method header to -(void) chooseImage:(id)sender and try presenting the popover from the UIBarButton you have on your toolbar.

此外,如果您使用ARC(它看起来像你),你必须坚持你的UIPopover,否则它将在仍然需要时发布此堆栈溢出帖子。你可能已经这样做了,但我想我会提高它,因为我看不出你是否/如何指定你的popoverController。

Also if you are using ARC (which it looks like you are) you have to hold on to your UIPopover otherwise it will be released when it is still required see this stack overflow post. You may already be doing this but I thought I would raise it as a I can't see if/how you have specified your popoverController.

这篇关于UIPopoverController和UIImagePickerController崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆