NSPredicateEditorRowTemplate and switching views
NSPredicateEditorRowTemplate and switching views
- Subject: NSPredicateEditorRowTemplate and switching views
- From: Arved von Brasch <email@hidden>
- Date: Tue, 5 May 2009 07:58:05 +1000
Hi Cocoa list,
I have noticed a strange bug in my NSPredicateEditorRowTemplate
implementation.
I have implemented a Pop-Up Pop-Up Level-Indicator template row to
allow users to sort by rating. The relevant code is below:
@synthesize levelIndicator;
- (id)copyWithZone: (NSZone *)zone {
id newRow = [super copyWithZone: zone];
NSLevelIndicatorCell *theCell = [[[NSLevelIndicatorCell alloc]
initWithLevelIndicatorStyle: NSRatingLevelIndicatorStyle] autorelease];
NSRect frame = [[[self templateViews] lastObject] frame];
frame.size.width = 65;
[theCell setEditable: YES];
[theCell setMinValue: 0.0];
[theCell setMaxValue: 5.0];
NSLevelIndicator *rating = [[[NSLevelIndicator alloc] initWithFrame:
frame] autorelease];
[rating setCell: theCell];
if ([self levelIndicator] != nil)
[newRow setFloatValue: [[self levelIndicator] floatValue]];
[newRow setValue: rating forKey: @"levelIndicator"];
return newRow;
}
- (NSArray *)templateViews {
NSMutableArray *allViews = [NSMutableArray arrayWithArray: [super
templateViews]];
if ([self levelIndicator] != nil) {
[allViews removeLastObject];
[allViews addObject: [self levelIndicator]];
}
return allViews;
}
- (void)setPredicate: (NSPredicate *)predicate {
[super setPredicate: predicate];
[[self levelIndicator] setObjectValue: [[(NSComparisonPredicate
*)predicate rightExpression] constantValue]];
}
This works fine if the row template is created fresh (ie empty with no
predicate assigned to it at creation). If the row template is created
in response to an edit instruction (edit an already existing
predicate), then the row template will appear correctly, but if a
different option is selected from the middle Pop-Up (eg "is not") the
level indicator view will disappear and will be replaced with the
original NSTextField.
I can't see anything obvious I'm doing wrong. As far as I can tell,
the appropriate branch of templateViews is being called when this
problem occurs. Can anyone shed any light on this?
Thanks in advance,
Arved von Brasch
_______________________________________________
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