NSPopUpButton + Bindings + Show All Option

2019-02-15 08:46发布

I'm trying to develop a NSPopUpButton that will serve as a filter to some datasource, let's say a NSArrayController that fills a table.

I can bind the NSArrayController from the menu to the selection keypath so the data is properly filtered, no problem with that.

Tricky part is, I want the content of this NSPopUpButton to rely on an NSArrayController using bindings, but I'd like to add a "Show All" menu item, or at least some item that doesn't come from the Core Data and performs some special action other than filtering the table using bindings and core data.

I'm trying to perform something like the NSPopUpButton used by finder in the filter bar, the last item of the menu performs a special action, while the others just filter the result.

I understand that the approach is to forget about bindings and do it everything programmatically, because I believe there's no way to mess up with the NSArrayController and bindings to add this custom menu item that doesn't rely on core data, but since I haven't found anything on the Apple Docs and here, I'd like to share my thoughts... any ideas?

1条回答
Evening l夕情丶
2楼-- · 2019-02-15 09:46

sounds to me like you're looking for the NSContentPlacementTagBindingOption.

you edit the NSMenu that's attached to the NSPopupButton as follows

setup of the pop-up menu button's menu

you then edit the settings on the NSMenuItem you want to have replaced with your array controller contents so that it has a meaningful tag associated with it

settings for the item that is going to be dynamically replaced by bindings

you then specify that tag as the content placement tag value on the NSPopupButton's bindings for the content/content* bindings.

bindings for the pop-up button itself

查看更多
登录 后发表回答