【问题标题】:ios7 NSInvalidArgumentException presenting UIPopoverControllerios7 NSInvalidArgumentException 呈现 UIPopoverController
【发布时间】:2013-09-21 20:27:24
【问题描述】:

试图显示一个 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 在呈现后就丢失了。

【问题讨论】:

    标签: ios uipopovercontroller ios7 uipopover


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-11
      相关资源
      最近更新 更多