I have an NSPopupButton that is bound to an NSArrayController in IB as follows:
Content -> ac.arrangedObjects
ContentValue -> ac.arrangedObjects.name
SelectedObject -> File's Owner.self.currentObject
The ac is bound to entities that are in my CD store (which are created when the
app starts up for the first time, following the code example for the "Type"
entity in the Grokking Recipes app from Zarra's Core Data book). I am using the
SelectedObject binding so that when the popup is changed, I immediately get the
selectedobject from the ac. This works like a charm.
Now when the view first appears, I'd like to set the NSPopupButton to a default
value, so I added this to awakeFromNib of my NSViewController to get the entity
with the name "defaultName":
NSManagedObjectContext *moc = [[NSApp delegate] managedObjectContext];
NSArray *results = [moc fetchObjectsForEntityName: @"MyObject"
withPredicateString: @"name == %@", @"defaultName"];
(that last line is based on this article:
http://cocoawithlove.com/2008/03/core-data-one-line-fetch.html)
then I set the currentObject to that entity:
self.currentObject = [results lastObject];
It works, I get the entity with defaultName as the initial value in the popup,
but for a split second, I first see something else, as if there is some delay
before the popup is set to the correct item.
Is this delay because I do a fetch in my CD store? If so is there a faster
way to do this, to prevent the delay?
- Koen.
_______________________________________________
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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [email protected]