Customizing left expression title in NSPredicateEditorRowTemplate
Customizing left expression title in NSPredicateEditorRowTemplate
- Subject: Customizing left expression title in NSPredicateEditorRowTemplate
- From: Mike Chambers <email@hidden>
- Date: Mon, 28 Dec 2009 14:42:51 -0800
I have am creating a simple NSPredicateEditorRowTemplate instance that
I instantiate like so:
--------
NSMutableArray *seriesExpressions = [NSMutableArray
arrayWithCapacity:[series count]];
for(NSString *s in series)
{
[seriesExpressions addObject:[NSExpression expressionForConstantValue:s]];
}
NSPredicateEditorRowTemplate * template =
[NSPredicateEditorRowTemplate alloc] initWithLeftExpressions:[NSArray
arrayWithObjects:[NSExpression expressionForKeyPath:@"series"], nil]
rightExpressions:seriesExpressions
modifier:NSDirectPredicateModifier
operators:[NSArray arrayWithObject:[NSNumber
numberWithInt:NSEqualToPredicateOperatorType]]
options:NSCaseInsensitivePredicateOption];
];
--------
Basically, the left expression is a key path named "series" and the
right expression is an Array of possible values.
This works great, except, I want the popup in the NSPredicateEditor to
display "Series" and not the keypath "series". I know how to do this
in Interface Builder, but since my right expressions are from a data
source, I cannot set this in interface builder.
How can I change the display title for the right expression?
I tried subclassing NSPredicateEditorRowTemplate and then overriding:
-------
- (NSArray *)templateViews
{
NSMutableArray* myviews = [[super templateViews] mutableCopy];
if(firstRun)
{
[myviews replaceObjectAtIndex:0 withObject:popup];
firstRun = FALSE;
}
return myviews;
}
with popup initiated like so:
-------
NSMenu *popupMenu = [[[NSMenu allocWithZone:[NSMenu menuZone]]
initWithTitle:@"Series"] autorelease];
NSMenuItem *menuItem = [[[NSMenuItem alloc] initWithTitle:@"Series"
action:nil keyEquivalent:@""] autorelease];
[menuItem setRepresentedObject:[NSExpression expressionForKeyPath:@"series"]];
[menuItem setEnabled:YES];
[popupMenu addItem:menuItem];
popup = [[NSPopUpButton alloc] initWithFrame:NSZeroRect pullsDown:NO];
[popup setMenu:popupMenu];
------
but this generates the following exception:
------
we were not able to find a popup item at view index 0 with title
Series. Available items are: <CFArray 0x115d780b0
[0x7fff7062bf20]>{type = immutable, count = 1, values = (
0 : <NSMenuItem: 0x115d73dc0 series>
-----
So, two questions:
1. Am I on the right track?
2. If not, how can I change the displayed title for the left expression?
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