When are objects from a core data store initially fetched?
When are objects from a core data store initially fetched?
- Subject: When are objects from a core data store initially fetched?
- From: Lee Falin <email@hidden>
- Date: Thu, 20 Dec 2007 19:02:10 -0500
So I have this wonderful NSOutlineView bound to an NSTreeController.
The NSTreeController uses core data to get some entities and
everything looks great. Now I'm trying to save the state of the
outline view (i.e. which nodes are expanded/collapsed) from session to
session.
Since I'm using Leopard and IB 3.0, I saw this handy checkbox
("Autosave Expanded Items"), so I thought "Great! More Cocoa magic
saving me from coding" so I checked that, entered a string for the
Autosave name, and thought that all was well. Except it wasn't.
Then I discovered that I still needed to add some datasource methods,
so I implemented:
-(id)outlineView:(NSOutlineView *)outlineView persistentObjectForItem:
(id)item
and
-(id)outlineView:(NSOutlineView *)outlineView itemForPersistentObject:
(id)object
Now that should work great, but it doesn't. Every time I expand a
node, outlineView:persistentObjectForItem: is called, and I see the
values being written into my plist file. When the app starts up, the
onlineView:itemForPersisitentObject is called, one time for every
value stored in the plist file, but alas this doesn't seem to help the
outline view, as none of the nodes end up expanded.
So then I read somewhere that I should walk the outline view myself
when the application starts up and expand the items myself, since I'm
using coredata and the data source methods don't work as one would
think in such cases, so I tried that.
At the applicationDidFinishLaunching notification I call a method in
my NSOutlineView subclass that is designed to do just that.
I retrieve my saved nodes from NSUserDefaults and start looping
through the outline view looking for matching nodes. Now here is my
big problem, for some reason (which I'm sure is obvious to someone),
my NSOutlineView returns 0 for totalRows at this point. Once I exit
the method, there are rows, but not immediately following the
"applicationDidFinishLaunching" notification.
So that brings me to my question. When exactly does an NSOutlineView
that is bound to core data through NSTreeController get its data? I
was sure that by the time "applicationDidFinishLaunching" fired that
it would have it, but apparently not.
_______________________________________________
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