【问题标题】:How to retrieve the current selection of an NSPopUpButtonCell?如何检索 NSPopUpButtonCell 的当前选择?
【发布时间】:2012-02-20 11:25:55
【问题描述】:

我在NSTableView 中使用NSPopUpButtonCell。弹出按钮绑定到ApplicationDelegate 提供的NSArray 属性。当我选择弹出按钮的菜单项时,我希望检索当前选择或其索引。我添加了一个 IBAction 以获取通知,并设置了一个NSMenuDelegate始终返回 index = 0。

// indexOfSelectedItem is always 0.
NSInteger indexOfSelectedItem = [m_popUpButtonCell indexOfSelectedItem];

我使用上述配置创建了一个example project。希望你能澄清一些事情。

【问题讨论】:

    标签: objective-c cocoa nstableview nsmenu nspopupbuttoncell


    【解决方案1】:

    文章Implementing To-One Relationships Using Pop-Up Menus回答了我的问题。
    我更新了示例项目

    【讨论】:

    • 我遇到了同样的问题。你能解释一下你做了什么吗?我将 NSPopUpButtonCell 的操作设置为仅检查所选索引 ([thePopUp indexOfSelectedItem]) 的方法,但它一直返回 0。我必须学习如何使用绑定吗?
    猜你喜欢
    • 2021-05-26
    • 1970-01-01
    • 2013-12-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多