Filtering a TableView

Discussion in 'Mac Programming' started by BadWolf13, Mar 17, 2010.

  1. BadWolf13 macrumors 6502

    Dec 17, 2009
    I've got a tableView with a data source as an NSMutableArray. I want to filter information in this tableView by a user entered criteria, however, I can't find anything in NSTableView or NSTableView delegate that would allow me to do that. It seems the only way is to create a second array that contains the filtered(or non-filtered) results and use that as the data source. It seems like there should be an easy way to filter a TableView, given that it's probably done a lot, so am I missing something?
  2. GorillaPaws macrumors 6502a


    Oct 26, 2003
    Richmond, VA
  3. BadWolf13 thread starter macrumors 6502

    Dec 17, 2009
    Unfortunately that's where I started. I found something in NSArrayController that's called Filtering, but doesn't really mean filtering in the same way that I do.
  4. BadWolf13 thread starter macrumors 6502

    Dec 17, 2009
    Ok, so I've got my tableView that's bound to an NSArrayController. Based on what I read, I created a method that returns an NSPredicate object which is then entered under the bindings screen for FilterPredicate of my NSArrayController. However, it's raising an exception whenever I run the program. This is the error message

    This is the code for my NSPredicate method

    -(NSPredicate *)tableFilter
    	NSPredicate *aPredicate = [NSPredicate predicateWithFormat:
    			@"ANY partsList.partNumber contains[c] %@", searchValue];
    	return aPredicate;
    Any thoughts on what I'm doing wrong here?

Share This Page