从模态视图控制器呈现弹出窗口

发布于 2024-09-14 15:10:45 字数 402 浏览 9 评论 0原文

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

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

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

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

I am trying to present a Popover from a button in a UIModalPresentationPageSheet. It crashes the app and returns the following message to the console:

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

My code works fine in a standard view controller. As the message suggests, there is something about the modal that prevents it displaying. I've done a fair amount of searching on this topic, but am not finding a solution. I have to believe it is possible, as I've seen something very similar in apps like 1Password.

Pointers and/or suggestions greatly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

毅然前行 2024-09-21 15:10:45

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

[_pPopOverController presentPopoverFromRect:CGRectMake(0, 0, 768, 900) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];   

The following code seems to be working for me, try this :

[_pPopOverController presentPopoverFromRect:CGRectMake(0, 0, 768, 900) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];   
花心好男孩 2024-09-21 15:10:45

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

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

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

}

I don't know which SDK did you use, but I don't get any exception with 5.1. I am showing a popover from a text field and the following code works:

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

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

}

许久 2024-09-21 15:10:45

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

I would bet that the problem is that you're passing a view controller instead of a view for the inView parameter. It's trying to fetch the .window for a UIViewController, and UIViewControllers don't have one, UIViews do.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文