UIPopoverController dealloc被称为ARC环境 [英] UIPopoverController dealloc getting called—ARC environment

查看:118
本文介绍了UIPopoverController dealloc被称为ARC环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在第二次显示弹出控制器时(在解除然后重新显示它之后),我收到以下错误:

While displaying a popover controller for a second time (after dismissing it and then re-displaying it), I get the following error:

终止应用由于未捕获的异常'NSGenericException',原因:' - [UIPopoverController dealloc]到达,而popover仍然可见。'

堆栈跟踪只是一堆十六进制和SIGABRT每次都在UIApplicationMain发生。这是按钮触发的代码:

The stack trace is only a bunch of hex and the SIGABRT happens at UIApplicationMain every time. Here's the code that the button triggers:

- (IBAction)createNewScore:(id)sender {
    if (self.pc)
        if (self.pc.popoverVisible)
            return;
        else
        // Breakpoint is hit here—crashes after this line
            [self.pc presentPopoverFromBarButtonItem:(UIBarButtonItem *)sender permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
    NGDocumentInfoViewController *documentInfoVC = [[NGDocumentInfoViewController alloc] initWithBlankDocumentTargetInManagedObjectContext:self.context];
    UINavigationController *navc = [[UINavigationController alloc] initWithRootViewController:documentInfoVC];
    UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(doneCreatingNewScore:)];
    UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelCreatingNewScore:)];
    navc.navigationBar.topItem.leftBarButtonItem = doneButton;
    navc.navigationBar.topItem.rightBarButtonItem = cancelButton;
    CGSize popoverSize = CGSizeMake(documentInfoVC.view.bounds.size.width, documentInfoVC.view.bounds.size.height);
    documentInfoVC.contentSizeForViewInPopover = popoverSize;
    UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:navc];
    popover.delegate = self;
    self.pc = popover;
    [popover presentPopoverFromBarButtonItem:(UIBarButtonItem *)sender permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}

我想保留修复此问题的popover,但是这是一个ARC环境,所以我没有保留。有没有办法让我修复错误(不关闭文件的ARC并且必须手动为整个文件做内存)?

I'd like to just retain the popover which would fix the issue, but this is an ARC environment so I don't have retain. Is there a way for me to fix the error (without turning off ARC for the file and having to manually do the memory for the entire file)?

编辑:popover存储为ivar:

The popover is stored as an ivar:

@property (strong) UIPopoverController *pc;






有没有人能解决这个问题(也许是ARC覆盖)?我将提交BR作为CodaFi建议,但解决方案仍然很好,因为这是一个重大项目的障碍。如果这是不可能的,那么我想我会自己动手。


Does anyone have a solution for this problem (maybe an ARC override)? I'll file a BR as CodaFi suggests, but a solution would still be nice, as this is a roadblock in a major project. If this is not possible, then I suppose I'll roll my own.

推荐答案

我遇到了同样的问题并修复了它通过将popover控制器保留在一个强实例变量中来建议并在使用在第二次操作中分配的新弹出控制器重置属性之前显式解除它。在您的示例中,您应该添加以下内容:

I have run into the same problem and fixed it by retaining the popover controller in a strong instance variable as suggested AND explicitly dismissing it before resetting the property with the new popover controller allocated in in the second run of the action. In your example, you should add something like this:

- (IBAction)createNewScore:(id)sender {
    if (self.pc) {
         [self.pc dismissPopoverAnimated:YES];
    }

这篇关于UIPopoverController dealloc被称为ARC环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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