【问题标题】:UIPopoverController dealloc getting called—ARC environmentUIPopoverController dealloc 被调用——ARC 环境
【发布时间】:2011-12-17 14:53:42
【问题描述】:

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

由于未捕获的异常“NSGenericException”而终止应用程序,原因:“-[UIPopoverController dealloc] 在弹出框仍然可见时到达。”

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

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

我只想保留可以解决问题的弹出框,但这是一个 ARC 环境,所以我没有保留。有没有办法让我修复错误(无需关闭文件的 ARC 并且必须手动为整个文件做内存)?

编辑:弹出框存储为 ivar:

@property (strong) UIPopoverController *pc;

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

【问题讨论】:

  • 你能在-[UIPopoverController dealloc] 上设置一个符号断点(使用Xcode 中断点导航器底部的+)并查看它在调试器中的停止位置吗?也许那里的堆栈跟踪可以提供一些关于释放弹出窗口的信息。
  • 断点没有被明确命中。它在崩溃之前在 UIApplcationMain 发生暂停,这似乎表明它至少部分与运行循环有关。我很想将其称为 ARC 的错误,因为它是如此低级。完整堆栈跟踪:bit.ly/rTf7f0
  • createNewScore是在主线程上执行的吗?
  • 是的,这里没有明确的线程。如果涉及线程,它们会在 Apple 的代码中,而不是我的。
  • 只是一点警告,与其他 ios 实现相比,UIPopover 作为一个整体是垃圾。提交您的错误报告,但根据我从参加 WWDC 的人那里听到的消息,Apple 不会很快修复弹出窗口。

标签: ios memory-management uipopovercontroller dealloc automatic-ref-counting


【解决方案1】:

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

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

【讨论】:

  • 创建实例变量对我有用。如果您不想使用按钮,触摸弹出框外部也会在稍后将其关闭。
【解决方案2】:

如果您的弹出框存储为强引用,则无法释放它。可以解除分配的唯一可能性是包含强引用的对象(在您的示例中为self)也被解除分配的情况。

我认为重要的问题是当弹出框可见时,你对视图做了什么。

如果你已经检查过了,那么它一定是一个框架错误。

【讨论】:

    猜你喜欢
    • 2015-04-06
    • 1970-01-01
    • 2014-07-16
    • 1970-01-01
    • 2013-10-19
    • 1970-01-01
    • 2016-08-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多