使用NSArrayController过滤单列NSTableView

Fat*_*tso 3 macos cocoa nstableview nsarraycontroller cocoa-bindings

我提出一张带有NSTableView(一列)NSSearchField和一张NSButton('添加')的表格.我想要的是将表视图的内容设置为字符串列表.此字符串列表位于被NSArray调用列表中.应根据搜索字段的内容(如果列表中的字符串)不包含搜索字段的内容来过滤此内容,而不再在表视图中显示该内容.

我不熟悉绑定,任何人都可以帮助我.

Ano*_*dya 5

我上传了一个项目,请检查一下.

一个粗略的想法是:(但通过看项目,理解更容易)

  1. 创建一个阵列控制器.

  2. 为阵列控制器对象设置

      Mode:Class
    
      Class Name: Your custom Class
    
    Run Code Online (Sandbox Code Playgroud)
  3. 收到的行动

      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)
  4. 引用绑定(来自表或来自此处的每列表).

  5. 对于搜索字段

     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)