Snow Leopard and NSPredicateRowTemplate
Snow Leopard and NSPredicateRowTemplate
- Subject: Snow Leopard and NSPredicateRowTemplate
- From: Arved von Brasch <email@hidden>
- Date: Sat, 29 Aug 2009 23:52:45 +1000
Hi Dev list,
I've just updated to Snow Leopard and have found that some of my code
no longer works. In particular, an NSPredicateRowTemplate where the
contents of the third popup button were filled with the contents of a
CoreData store. This is the relevant code:
- (id)copyWithZone: (NSZone *)zone {
id newRow = [super copyWithZone: zone];
[newRow setItems: items];
popUpItems = [[NSPopUpButton alloc] initWithFrame: [[[self
templateViews] lastObject] frame] pullsDown: NO];
for (NSManagedObject *listItem in [newRow items]) {
[popUpItems addItemWithTitle: [listItem valueForKey: @"name"]];
[[popUpItems lastItem] setRepresentedObject: [[listItem objectID]
URIRepresentation]];
}
[newRow setPopUpItems: popUpItems];
return newRow;
}
- (NSArray *)templateViews {
NSMutableArray *views = [NSMutableArray arrayWithArray: [super
templateViews]];
if ([self popUpItems] != nil) {
[views removeLastObject];
[views addObject: [self popUpItems]];
}
return views;
}
- (void)setPredicate: (NSPredicate *)predicate {
NSUInteger itemIndex;
NSPopUpButton *popUpButton = [[self templateViews] lastObject];
NSMenuItem *selectedItem;
for (itemIndex = 0; itemIndex < [popUpButton numberOfItems]; itemIndex
++) {
selectedItem = [popUpButton itemAtIndex: itemIndex];
if ([[[(NSComparisonPredicate *)predicate rightExpression]
constantValue] isEqualTo: [selectedItem representedObject]]) {
[popUpButton selectItem: selectedItem];
break;
}
}
if ([(NSComparisonPredicate *)predicate predicateOperatorType] ==
NSNotEqualToPredicateOperatorType)
[[[self templateViews] objectAtIndex: 1] selectItemAtIndex: 1];
}
Where 'items' is the NSArrayController that contains the CoreData
backed objects, and the first template is connected to this in
Interface Builder. I thought this code to be the correct way to do
this, and it worked fine in Leopard. The error result it generates is
below:
HIToolbox: ignoring exception 'In <NSPredicateEditor: 0x100632b40>
with template <TPListRowTemplate 0x1003400c0: [listItems] [4, 5]
["Default"]>, we were not able to find a popup item at view index 2
with title Default. Available items are: <CFArray 0x100342850
[0x7fff70f10f00]>{type = immutable, count = 2, values = (
0 : <NSMenuItem: 0x100342300 Test 1>
1 : <NSMenuItem: 0x1003425b0 Test 2>
)}' that raised inside Carbon event dispatch
and then a stack trace.
As far as I can see, the documentation doesn't appear to have
changed. What is the correct way to handle this now?
Thanks in advance,
Arved
_______________________________________________
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