• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Having problems understanding NSPredicateEditor
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Having problems understanding NSPredicateEditor


  • Subject: Having problems understanding NSPredicateEditor
  • From: Mike Chambers <email@hidden>
  • Date: Sat, 26 Dec 2009 22:06:36 -0800

I have an application that contains a NSTableView of Card data types.
The NSTableView gets its data from an NSArray of Card instances.

I want to allow the user to be able to filter the view based on the
Card fields. I know I need to use a NSPredicateEditor to present the
UI for the user, and to create the NSPredicate instances. However, I
cannot wrap my head around how this works, and cannot get a simple
example working (with a single rule). I have spent the last two days
reading up on it, and it is just not clicking for me.

So, does anyone have a very simple example of how to use
NSPredicateEditor programmatically?

I want to be able to allow the user to potentially filter on multiple
fields, but would be happy if I can get a single field to work right
now.

Here is the current predicate I am using with a NSSearchField:

NSPredicate *namePredicate = [NSPredicate
predicateWithFormat:@"cardName contains[c] %@", searchString];
[filteredCards filterUsingPredicate:namePredicate];

Card has a property (NSString) named "cardName".

I have tried to programmatically add a NSPredicateEditorRowTemplate,
but when I do this, nothing shows up in the editor at runtime.

NSPredicateEditorRowTemplate *template = [[NSPredicateEditorRowTemplate alloc]
 initWithLeftExpressions:[NSArray arrayWithObjects:[NSExpression
expressionForKeyPath:@"cardName"], nil]
			rightExpressions:[NSArray arrayWithObjects:[NSExpression
expressionForConstantValue:@"Foo"], nil]
			modifier:NSDirectPredicateModifier
										  operators:[NSArray arrayWithObject:[NSNumber
numberWithInt:NSContainsPredicateOperatorType]]
			options:NSCaseInsensitivePredicateOption
 ];

predicateEditor.rowTemplates = [NSArray arrayWithObject:template];

I am really stumped on this one, and would appreciate it if someone
could help nudge me in the right direction. Does anyone have a simple
example of how to construct NSPredicateEditorRowTemplate that will
create a filter like so:

cardName contains USER_INPUT

I think if I can get that working, then it will put me over the hump
and I can figure out the rest.

mike
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Having problems understanding NSPredicateEditor
      • From: Timothy Stafford Larkin <email@hidden>
  • Prev by Date: Strange Problems with IBPlugin
  • Next by Date: Re: [iPhone] Refreshing a UITableView in a UINavigationController...
  • Previous by thread: Re: Strange Problems with IBPlugin
  • Next by thread: Re: Having problems understanding NSPredicateEditor
  • Index(es):
    • Date
    • Thread