【问题标题】:NSWindow Full size content view and launching popover causes errorNSWindow 全尺寸内容视图和启动弹出框导致错误
【发布时间】: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


    【解决方案1】:

    因此,来自同行的有用意见。我找到了解决操作系统中似乎存在错误的方法。

    而不是像往常一样调用弹出框。喜欢:

    @IBAction func thebuttonclicked(sender: AnyObject) {
        var theview = thebutton
        var thebounds = thebutton.bounds
        popver.showRelativeToRect(thebounds, ofView: theview, preferredEdge: NSMinXEdge)
    }
    

    我必须像这样 dispatch_async 到一个启动弹出框函数:

    @IBAction func thebuttonclicked(sender: AnyObject) {
        dispatch_async(dispatch_get_main_queue()) {
            self.launchmypopover()
        }
    }
    
    
    func launchmypopover(){
        var theview = thebutton
        var thebounds = thebutton.bounds
        popver.showRelativeToRect(thebounds, ofView: theview, preferredEdge: NSMinXEdge)
    }
    

    我就这个问题提交了一份雷达报告。在发布修复之前,我必须使用此方法。

    【讨论】:

    • 感谢分享解决方案 :)
    • 确实!感谢您分享这一见解。
    猜你喜欢
    • 2021-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-28
    • 2017-10-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多