Fat*_*tso 3 macos cocoa nstableview nsarraycontroller cocoa-bindings
我提出一张带有NSTableView
(一列)NSSearchField
和一张NSButton
('添加')的表格.我想要的是将表视图的内容设置为字符串列表.此字符串列表位于被NSArray
调用列表中.应根据搜索字段的内容(如果列表中的字符串)不包含搜索字段的内容来过滤此内容,而不再在表视图中显示该内容.
我不熟悉绑定,任何人都可以帮助我.
我上传了一个项目,请检查一下.
一个粗略的想法是:(但通过看项目,理解更容易)
创建一个阵列控制器.
为阵列控制器对象设置
Mode:Class
Class Name: Your custom Class
Run Code Online (Sandbox Code Playgroud)收到的行动
add: to the button that will add new objects, typically labelled with +
remove:to the button that will add new objects., typically labelled with -
Run Code Online (Sandbox Code Playgroud)引用绑定(来自表或来自此处的每列表).
对于搜索字段
Bindings, Predicate to Array Controller
ControllerKey : filterPredicate
Predicate Format : <class property> contains $value
(if to search in multiple table columns then <class property 1> contains $value || <class property 2> contains $value etc…. )
Run Code Online (Sandbox Code Playgroud)