Ordered CoreData won't preserve selection
Ordered CoreData won't preserve selection
- Subject: Ordered CoreData won't preserve selection
- From: "Matt Ball" <email@hidden>
- Date: Tue, 4 Apr 2006 00:57:58 -0400
I've begun redesigning my app using CoreData, and I've run into a bit
of a snag. I require that my data (which is displayed in an
NSOutlineView) maintain the order the user specifies (ie: the order in
which they add the entities, or the order the specify by
drag/dropping). I've created an "order" integer key in my entity, and
I call the following every time I add a new layer (I haven't
implemented anything for removing/dragging yet, but they should be
fairly similar):
- (void)increaseOrderForParent:(id)parent forObject:(id)newLayer
atIndex:(int)index {
NSArray* childrenObjects = nil;
if(parent) {
childrenObjects = [[parent valueForKey: @"children"] allObjects];
} else {
childrenObjects = [self content];
}
childrenObjects = [NSArray arrayWithArray:[childrenObjects
sortedArrayUsingDescriptors:[self sortDescriptors]]];
NSManagedObject* layer;
unsigned int i;
for( i=index; i<[childrenObjects count];i++ ) {
layer = [childrenObjects objectAtIndex:i];
[layer setValue:[NSNumber numberWithUnsignedInt:i+1] forKey:@"order"];
}
[newLayer setValue:[NSNumber numberWithUnsignedInt:index] forKey:@"order"];
}
This seems to be working fine, except that my outlineview refuses to
preserve the selection. Any time I switch away from and back to my
app, the data stays in the correct order, but the top item gets
selected, regardless of what was previously selected. This is
unacceptable behavior for my app.
Does anyone know: 1) Why CoreData is not preserving my selection,
despite "preserve selection" being checked in IB? 2) How I can fix it,
and/or 2b) If there is a better way to update my "order" key which
might prevent this problem entirely?
Any help would be greatly appreciated.
Thanks,
Matt Ball
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden