0

尝试显示 UIPopoverController 在 ios 7 中崩溃,而它在 ios6 及之前的版本中工作。错误信息是

由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[UIPopoverController _commonPresentPopoverFromRect:inView:permittedArrowDirections:animated:]:无法从没有窗口的视图中呈现弹出框。”

事实上,这是真的:self.view.window 在 ios7 中是 nil 而在 ios6 中不是。

编码:

UIPopoverController *pop = [[UIPopoverController alloc] initWithContentViewController:aViewCtl];
pop.delegate = self;
[pop presentPopoverFromRect:CGRectMake(aRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

视图在 loadView 方法中以编程方式创建(并分配给 self.view),而弹出框在按下按钮后显示。有什么建议吗?

编辑:看起来问题是在显示弹出窗口之前使用模式视图,尽管将其关闭。不知何故, self.view.window 在呈现后丢失了。

4

1 回答 1

0

我发现的最佳解决方案是检查 self.view.window。如果为 nil,则在视图中注册一个委托并等待didMoveToWindow,它将调用委托并继续创建并显示弹出框。

于 2013-09-24T08:46:36.997 回答