【发布时间】: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