【发布时间】:2019-02-26 02:38:38
【问题描述】:
我制作了一个自定义 CustomView.xib 。它归 NSView 的子类 CustomView.swift 所有。现在,我只需添加 NSView 并将其类设置为 CustomView,就可以轻松地在 Storyboard 中重用 CustomView。问题是我在 CustomView.xib 中有一个按钮,我想在单击时显示一个弹出框 MyPopoverViewController 。我搜索了一下,发现为了呈现一个弹出框,我需要使用如下方法:
presentViewController(viewController: NSViewController, asPopoverRelativeTo: NSRect, of: NSView, preferredEdge: NSRectEdge, behavior: NSPopover.Behavior)
问题是这个方法只能在 NSViewController 中使用。但我没有。我想从 NSView 中触发弹出窗口。我现在该怎么办?这应该是可能的,因为 NSAlert 无处不在,它甚至不将任何 NSViewController 作为参数。所以应该有一种方法可以在没有任何 NSViewController 的情况下呈现 popover。
【问题讨论】: