Re: NSArrayController addObject or insertObject:atArrangedObjectIndex:
Re: NSArrayController addObject or insertObject:atArrangedObjectIndex:
- Subject: Re: NSArrayController addObject or insertObject:atArrangedObjectIndex:
- From: BareFeet <email@hidden>
- Date: Tue, 22 Sep 2009 22:40:30 +1000
On 22/09/2009, at 5:18 PM, Dave Keck wrote:
It looks like dataRowsController is no longer a valid object by the
time -addObject:/-insertObject: is called on it.
Thanks for the reply Dave.
That doesn't seem to be the problem. dataRowsController is hooked up
via Interface Builder to the NSArrayController. I know it's valid
because the method in my code [dataRowsController selectionIndex]
works, as does a test method [dataRowsController content].
I think I've found the problem though.
It seems that the addObject: or insertObject: method call on the
controller actually calls the getter then the setter for the whole
array. I had an NSLog in my getter that was actually causing the error:
- (void) setDataRows:(NSMutableArray *)newDataRows
{
NSLog(@"setDataRows: count == %@", [newDataRows count]);
[dataRows autorelease];
dataRows = newDataRows;
[dataRows retain];
}
Once I removed the NSLog line (or just the [newDataRows count]
method), it works fine.
Two followup questions:
1. Why can't I use the array count in the NSlog like that?
2. Does addObject: and insertObject: actually just get the whole
array, add the extra object, then write the whole array back to the
instance variable? I thought it would be more efficient than that.
Thanks,
Tom
BareFeet
_______________________________________________
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