问题描述
我展示了一个带有NSTableView
(一列),NSSearchField
和NSButton
(添加")的工作表.我想要的是将表视图的内容设置为字符串列表.此字符串列表位于名为 list 的NSArray
中.该内容应根据搜索字段的内容进行过滤(如果 list 中的字符串)不包含搜索字段的内容,则不再显示在表格视图中.
I present a sheet with an NSTableView
(one column), an NSSearchField
and an NSButton
('Add').What I want is to set the content of the table view to a list of strings. This list of strings is in an NSArray
called list. This content should be filtered based on the content of the search field (if a string in list) does not contain the content of the search field it is not shown in the table view anymore.
我对绑定不熟悉,有人可以帮我吗?
I'm not familiar with bindings, can anyone help me out.
推荐答案
我已经上传了项目,请检查.
I have uploaded a project, kindly check.
一个大概的想法是:(但是通过查看项目更容易理解)
A rough idea how to do is as: (however understanding is easier by seeing the project)
-
创建阵列控制器.
Create an Array Controller.
设置数组控制器对象
Mode:Class
Class Name: Your custom Class
已收到的操作
Received Actions
add: to the button that will add new objects, typically labelled with +
remove:to the button that will add new objects., typically labelled with -
引用绑定(从表或表的每一列开始).
Referencing Bindings(either from table or from here for each column of table).
用于搜索字段
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…. )
这篇关于使用NSArrayController过滤单列NSTableView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!