【发布时间】:2015-02-16 22:57:03
【问题描述】:
单击按钮以显示弹出框时在控制台中看到此错误后:
unlockFocus called too many times. Called on <NSButton: 0x6180001404d0>
在最终找到问题之前,我复制了我的应用程序并将其剥离到骨头上。 我可以在新项目中复制它而不会失败。
请问是否有人知道为什么会出现这种情况,并且知道解决方法,我在下面的新项目中显示了复制此错误的方法..?
创建新的基于文档的项目。 添加一个按钮、一个自定义视图以及在弹出视图中显示自定义视图所必需的:
class Document: NSDocument {
@IBOutlet var thebutton: NSButton!
@IBOutlet var popver: NSPopover!
override init() {
super.init()
// Add your subclass-specific initialization here.
}
@IBAction func thebuttonclicked(sender: AnyObject) {
var theview = thebutton
var thebounds = thebutton.bounds
popver.showRelativeToRect(thebounds, ofView: theview, preferredEdge: NSMinXEdge)
}
现在这就是导致问题的原因...将 IB 中的窗口设置为“显示完整大小的内容”
运行应用程序,单击按钮打开弹出框时会出现控制台错误:
unlockFocus called too many times. Called on <NSButton: 0x6180001404d0>
虽然弹出框始终有效,但未在 IB 中为窗口选择“全尺寸内容视图”会导致永远不会看到错误。
【问题讨论】:
标签: macos swift nswindow nspopover