Predicate and Table View/Array Controller

I have a table view connected to an array controller with a “dataSource”.
If I add a “search field” and connect to the array controller the table view will show only the found data rows.
Now if I want to search for “non-textual” programatic things I can use a predicate and search the “dataSource” and find the matching rows.
Is there a easy way to make the table view behave like above.
If I change something the changes are directly saved to the dataSource.

The general idea is for your data to have a field that is suitable for searching in the first place. The search field can have multiple Predicates — when you have more than one, the Display Name is used.

Thanks Shane.

Question was asked wrong.
I know that I can have multiple Predicate Bindings.
But they only work for textual search (at least for me).
For example:

set searchValList to {"", defGap, maxChars, maxPars, defCPS, minDur, maxDur}
set searchId to ((defaults's objectForKey:"searchId") as integer) + 1
if searchId > 1 then
	set searchString to (item searchId of {"", "gapFrames < ", "maxChars > ", "parCount > ", "theCPS > ", "durTime < ", "durTime > "} & item searchId of searchValList) as text
	tell current application's NSPredicate to set aPredicate to predicateWithFormat_(searchString)
	set theList to subsData's filteredArrayUsingPredicate:aPredicate
end if

What would be the way to update the table view and keep the connection to the dataSource.

It sounds like you want to change the binding programmatically. That means using bind:toObject:withKeyPath:options: (and unbind:). Probably do-able in ASObjC, but it’ll probably take some figuring out.

Thanks again Shane.
Seems to be a bit beyond my skills at the moment :slight_smile:

But is there an easy way to “swap” table view content and update the data source once changes are made?

I’m not sure what you mean by using an array controller with a data source — it’s usually a case one or the other. But either way, you control the content.

You can apply a filter to an array controller programatically: just use setFilterPredicate:.

1 Like

Many Thanks Shane,

I didn’t see your reply.
It solves my problem.
It would have saved me a lot of time if I would have seen the reply.

Again thanks.