I have an NSTableView that contains a few columns that are populated with data. How do I set up a search bar that can filter the rows based on the content of a specific column? I am looking for the type of thing that is done with Spotlight in the Finder or the search bar in iTunes that can filter songs by metadata.
Share
Can your data source be managed by NSArrayController?
There are 2 standard approaches. The first (pre-Tiger) technique is to subclass NSArrayController, overriding arrangeObjects. The second (post-Tiger) is to bind NSSearchField’s predicates to the NSArrayController’s filterPredicate. In either case, bind your view properties to the controller’s
arrangedObjectkey (e.g. bind the “name” NSTableColumn to the controller’sarrangedObjects.namekey and bind the NSTableView’s content toarrangedObjects). You might want to read up on writing predicates.