使用NSArrayController过滤单列NSTableView [英] Filtering a single-column NSTableView using NSArrayController

查看:73
本文介绍了使用NSArrayController过滤单列NSTableView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我展示了一个带有NSTableView(一列),NSSearchFieldNSButton(添加")的工作表. 我想要的是将表视图的内容设置为字符串列表.此字符串列表位于名为 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)

  1. 创建阵列控制器.

  1. 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆