Filtering a single-column NSTableView using NSArrayController

筅森魡賤 提交于 2019-12-06 07:21:48

问题


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.


回答1:


I have uploaded a project, kindly check.

A rough idea how to do is as: (however understanding is easier by seeing the project)

  1. Create an Array Controller.

  2. Set for Array controller Object

      Mode:Class
    
      Class Name: Your custom Class
    
  3. 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 -
    
  4. Referencing Bindings(either from table or from here for each column of table).

  5. For search field

     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…. )
    


来源:https://stackoverflow.com/questions/14121152/filtering-a-single-column-nstableview-using-nsarraycontroller

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