UIPopoverController dealloc 被调用ߞARC 环境
当第二次显示弹出窗口控制器时(在关闭它然后重新显示它之后),我收到以下错误:
由于未捕获的异常“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,但解决方案仍然很好,因为这是一个主要项目的障碍。如果这是不可能的,那么我想我会自己推出。
While displaying a popover controller for a second time (after dismissing it and then re-displaying it), I get the following error:
Terminating app due to uncaught exception 'NSGenericException', reason: '-[UIPopoverController dealloc] reached while popover is still visible.'
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];
}
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)?
Edit: The popover is stored as an ivar:
@property (strong) UIPopoverController *pc;
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您的弹出窗口存储为强引用,则无法释放它。可以释放它的唯一可能性是包含强引用的对象(示例中的 self )也被释放的情况。
我认为重要的问题是,当弹出窗口可见时,您正在对您的视图做什么。
如果您已经检查过这一点,那么它一定是一个框架错误。
If your popover is stored as strong reference, it can't be deallocated. The only possibility when it can be deallocated is in the situation when the object containing the strong reference (
self
in your example) is also deallocated.I think the important question is what are you doing with your views when the popover is visible.
If you have already checked this, than it must be a framework bug.
我遇到了同样的问题,并通过按照建议将弹出窗口控制器保留在强实例变量中并在使用第二次运行操作中分配的新弹出窗口控制器重置属性之前显式解除它来修复它。在您的示例中,您应该添加如下内容:
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: