【问题标题】:calling an action on clicking NSPopupButton在点击 NSPopupButton 时调用一个动作
【发布时间】:2019-01-03 02:12:50
【问题描述】:

我有一个 NSPopupButton,单击时会显示一个下拉菜单。此菜单由 NSArray 填充。现在,如果我单击下拉菜单中的一项,我可以选择它并确定选择的内容等。 我想要做的是当用户单击 NSpopupbutton 时,更新下拉菜单,然后让用户选择其中一项。 当我简单地选择下拉菜单(不单击其中的任何一项)时,我无法找到如何调用 IBAction 方法。单击菜单中的项目会导致 IBAction,但我只想单击 NSPopupButton 中的向下箭头来触发操作。有任何想法吗 ?谢谢。

【问题讨论】:

    标签: cocoa nspopupbutton


    【解决方案1】:

    NSPopupButton 在点击时会发送一个NSPopUpButtonWillPopUpNotification。让您的控制器对象监听该通知并通过更新下拉菜单做出响应。

    【讨论】:

      【解决方案2】:

      接受的答案有效,但现在它被称为 NSPopUpButton.willPopUpNotification

      在 Swift 4.x 中,我的代码如下所示:

      NotificationCenter.default.addObserver(self,
                       selector: #selector(dropdownMenuOpened),
                       name: NSPopUpButton.willPopUpNotification,
                       object: nil)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-08-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多