4

我正在尝试从 UIModalPresentationPageSheet 中的按钮呈现弹出框。它使应用程序崩溃并向控制台返回以下消息:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Popovers cannot be presented from a view which does not have a window.'

我的代码在标准视图控制器中运行良好。正如消息所暗示的那样,模态有一些东西阻止它显示。我已经对此主题进行了大量搜索,但没有找到解决方案。我必须相信这是可能的,因为我在 1Password 等应用程序中看到了非常相似的东西。

非常感谢指针和/或建议。

4

3 回答 3

0

我不知道您使用的是哪个 SDK,但 5.1 没有任何异常。我正在显示来自文本字段的弹出窗口,并且以下代码有效:

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {

[_popController presentPopoverFromRect:textField.frame
                                inView:textField.superview
              permittedArrowDirections:UIPopoverArrowDirectionAny
                              animated:YES];
return NO;

}

于 2012-07-22T10:17:02.567 回答
0

我敢打赌,问题在于您传递的是视图控制器而不是 inView 参数的视图。它试图获取 UIViewController 的 .window,而 UIViewControllers 没有,UIViews 有。

于 2014-06-05T23:34:31.557 回答
0

以下代码似乎对我有用,试试这个:

[_pPopOverController presentPopoverFromRect:CGRectMake(0, 0, 768, 900) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];   
于 2010-11-04T07:28:29.397 回答