0

I am building a notes-like application. It has a NStableview displaying all notes' titles, and a NStextview displaying the plain text of the selected note. I am using bindings and core data. I want to have a search feature:

1. the tableview only shows the notes that contains the text you query
2. the textview displays the first note, and highlight the text you queried

I just started doing Cocoa development, and not sure how to implement this, and what classes and methods should I use. I googled around, and didn't find a good answer.

Can anyone please give me some ideas and resource to look at? Thanks.

Jensen
  • 1,653
  • 4
  • 26
  • 42

1 Answers1

0

If you have an NSSearchField in your xib, you can go to the bindings inspector and bind a predicate to it, instead of a value. Leave the model key path empty, and in Predicate Format (pretend your model is storing the text content with the attribute name "textContent") put this:

textContent contains[c] $value

The [c] tells it to search regardless of the case. It will automatically update your NSTableView if you're using bindings for that.

As far as highlighting your content, I'm not sure there's an easy way to do this with bindings (there might be).

Edit: Make sure you bind it to your NSArrayController, even though you leave the model key path blank

macandyp
  • 817
  • 9
  • 21
  • I am overriding the arrangeObjects method of NSArrayController, which is discussed in [this post](https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CocoaBindings/Tasks/filtering.html). – Jensen Jan 25 '13 at 23:18