English 中文(简体)
使用数组控制器上的谓词来过滤相关对象。
原标题:
  • 时间:2009-05-12 18:58:58
  •  标签:

I have an application using Core Data and bindings. I want to have an NSSearchField that can search through an NSArrayController bound to an NSTableView. The array controller contains Core Data objects that have a "name" field. I have setup the NSSearchField like this:

Bind To: the array controller
Controller Key: filterPredicate
Predicate Format: name contains[c] $value

这个运作良好。我想扩展它,使它能够搜索与数组控制器中对象相关的字段。 数组控制器中的每个对象都与另一种名为“标签”的对象具有一对多的关系,该对象具有名为“名称”的字段。 我尝试了以下操作:

Bind To: the array controller
Controller Key: filterPredicate
Model Key Path: tags
Predicate Format: name contains[c] $value

This however does not work. Nothing happens in the NSTableView when text is input into the NSSearchField. What is wrong with it?

最佳回答

Binding to tags as the model key path attempts to bind the search field predicate to the key path arrayController.filterPredicate.tags. Since the filterPredicate property of the array controller doesn t have a tags property, you re probably gettings key not found exceptions that are being logged silently. Instead, recalling that the filterPredicate of an NSArrayController is applied to the members of the array, you want the binding to be set up something like this:

Bind To: <array controller>
Controller Key: filterPredicate
Predicate Format: ANY self.tags contains[c] $value

self.tags could be written as just tags, but I think this makes it clearer that tags is a property of the object to which the predicate is being applied.

问题回答

暂无回答




相关问题
热门标签