NSArrayController: delay in setting selection, inserting item?
NSArrayController: delay in setting selection, inserting item?
- Subject: NSArrayController: delay in setting selection, inserting item?
- From: Joshua Scott Emmons <email@hidden>
- Date: Sun, 26 Jun 2005 14:38:48 -0400
I have an NSTableVie bound to an NSArrayController that's getting its
data from CoreData.
The NSManagedObject that I want to insert into the table has a date
field that I want to set with [NSDate
dateWithNaturalLanguageString:@"now"]
I want the newly-inserted record to be selected in the table when all
is said and done.
I though I could do this:
[myArrayController setSelectsInsertedObjects:YES];
.
.
.
-(IBAction)insert:(id)sender{
[myArrayController insert:sender];
[[myArrayController selection] setValue:[NSDate
dateWithNaturalLanguageString:@"now"]
forKey:@"myDate"];
}
But this (somehow) sets the date of whatever was selected when I
clicked the insert button and THEN inserts the new blank record. It's
as though the array controller is setting the selection some time
long after it inserts the record.
Then I thought I might be able to fix the problem like this:
[myArrayController setSelectsInsertedObjects:NO];
.
.
.
-(IBAction)insert:(id)sender{
NSManagedObject *managedObject = [NSEntityDescription
insertNewObjectForEntityForName:@"MyEntity" inManagedObjectContext:
[self managedObjectContext]];
[managedObject setValue:[NSDate
dateWithNaturalLanguageString:@"now"] forKey:@"completed"];
[myArrayController setSelectedObjects:[NSArray
arrayWithObject:managedObject]];
}
But again this doesn't work because, apparently, the array controller
isn't aware of the object at the time when I call
setSelectedObject:. It's aware of it afterwards (the new record
shows up in the table and everything), but not immediately after
creating the object.
How am I supposed to pre-fill a new record with computed values AND
select that record?
Many thanks!
-Joshua Emmons
_______________________________________________
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