NSArrayController content array vs arrangedObjects
NSArrayController content array vs arrangedObjects
- Subject: NSArrayController content array vs arrangedObjects
- From: email@hidden
- Date: Thu, 19 Jul 2007 21:31:56 -0700
Problem: I am trying to accomplish bulk deletes and (re)insertions into an NSArrayController/bound ivar.
I have a NSTableView bound to an NSArrayController's content:arrangedObjects, selectionIndexes, and sortDescriptors (each column is bound to a key in an ivar). The NSArrayController is bound to an NSMutableArray ivar in an NSDocument subclass.
I can delete material from the NSArrayController in a KVO-compliant manner by using[... removeObjectsAtArrangedObjectsIndexes: [tableView selectedRowIndexes]] . This will call one of two KVO methods:
-(void)insertObjects:(NSArray *)otherArray inTheFooAtIndexes:(NSIndexSet *)indexes;
-(void)removeObjectsInTheFooAtIndexes:(NSIndexSet *)indexes;
But it will do it for every object, generating a KVO notification. It can be slow.
I was looking at mmalc's bookmarks example of programmatically bulk updating an ivar:
http://homepage.mac.com/mmalc/CocoaExamples/controllers.html (see Batch modification of collections)
So i simply call a method on my ivar:
- (void)removeObjectsInTheFooAtIndexes:(NSIndexSet *)indexes
{
[self willChange:NSKeyValueChangeRemoval valuesAtIndexes:indexes
forKey:@"theFoo"];
[[self theCues] removeObjectsAtIndexes:indexes];
[self didChange:NSKeyValueChangeRemoval valuesAtIndexes:indexes
forKey:@"theFoo"];
}
however, I am having the damnedest time specifying an IndexSet to remove from the ivar. It seems that the [NSArrayController selectionIndexes] returns an NSIndexSet from the arrangedObjects array and not the contentArray. Since my ivar matches the contentArray(?) whenever I delete something in my ivar, I am deleting the wrong items.
How can I address this?
This problem is similiar to one from 2006 I saw on the lists:
http://www.cocoabuilder.com/archive/message/cocoa/2006/3/5/158058
_______________________________________________
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