I am currently building an ASOC application and I am stuck with an issue regarding search fields…
Currently the application I am building is comprised of a table view and a corresponding array controller to hold all the data. The table is comprised of many columns and each column has it own individual search fields. I am using bindings and predicate on the search fields.
Typical use of the application would have users searching on (at least) two of the columns… with each search filtering from the results of the previous search… i.e. user would search by “field A” (results would filter from array controller) THEN user would like to search by “field B” (which would then filter the previously filtered data from “field A”).
Xcode’s default behavior removes the first search (in this case, field A) before it attempts the second (for field B). Is there a means in either ASOC or cocoa bindings to string the two searches together?
Sorry the the vague details. This is my first time posting, and i didn’t want to provide information overload. If there is more details you would like, please feel free to let me know.
To search on multiple fields, you generally use a single search field with multiple predicates. It’s a bit tricky to set up, but when you have more than one predicate, the Display Name filed in the bindings inspector appears in the menu inside the search field.
I’m not saying you can’t make it work how you describe – but it would probably require multiple array controllers or doing it without bindings.
Thank you Shane for confirming my suspicions that this wouldn’t be possible with bindings.
When I started building the application, I had initially built it using a single search field with multiple predicates as you mentioned. Unfortunately, using that method, a user can still only search on one predicate. When selecting the 2nd, the first is cleared (much like I’m seeing in the multiple search field scenario I am currently trying to implement).
It may not be too hard to do it without bindings. Connect the fields to action handlers, and in them build predicates accordingly. But instead of setting the predicate property of the array controller with this value, get its existing predicate and create a compound predicate with the two, and use that as the new predicate.