NSPopUpButton + Bindings + Show All Option

天涯浪子 提交于 2019-12-09 01:05:29

问题


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:


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

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

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

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



来源:https://stackoverflow.com/questions/11405317/nspopupbutton-bindings-show-all-option

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!