On Dec 7, 2008, at 8:29 AM, Matteo Manferdini wrote:

NSManagedObject *newObject = [arrayController newObject];
[arrayController setSelectedObjects:[NSArray arrayWithObject:newObject]];

If I call [arrayController selectedObject] just before these two
lines, the array returned contains the actual selection, but if I call
it just after them, it returns an empty array.

I'm not sure why this is "weird"? -- it's certainly not a bug, it's behaving correctly.

newObject doesn't insert the object into the array.

Assuming that you have automatically prepares content set for the array controller, then newObject will be added later when the array controller receives an NSManagedObjectContextObjectsDidChangeNotification notification:

- (void)setAutomaticallyPreparesContent:(BOOL)flag

"If flag is YES and a managed object context is set, the initial content is fetched from the managed object context using the current fetch predicate. The controller also registers as an observer of its managed object context. It then tracks insertions and deletions of its entity using the context's notifications, and updates its content array as appropriate."


So when you invoke 'setSelectedObjects:[NSArray arrayWithObject:newObject]', newObject isn't in the array...


If you want to immediately insert and select the new object, then do so, e.g. per <http://lists.apple.com/archives/Cocoa-dev/2008/Dec/msg00534.html >

- (IBAction)newAtTop:sender {

   id newObject = [arrayController newObject];
   [arrayController insertObject:newObject atArrangedObjectIndex:0];
   [tableView editColumn:0 row:0 withEvent:nil select:YES];
   [newObject release];
}


mmalc

_______________________________________________

Cocoa-dev mailing list ([email protected])

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to