Core Data question about data load at launch

Status
Not open for further replies.
I'm new to Cocoa and Core Data and I'm trying to figure out how to call a method after data is loaded into a table at application launch.

I have a custom view that displays a chart based on the row selected in the table bound to a core data model. I created the table in interface builder by dragging a "Core Data Entity" from the Library window. I successfully bound some other controls to the selected core data entity. When the application launches, it automatically selects the top entry in the list and populates the other text fields that I bound to the model. What I'm trying to do is to get the custom view to display based on the top entry that automatically is selected. At the time of execution of applicationDidFinishLaunching:, the table view has not yet loaded data from the persistent store.

I cannot find what I'm looking for in the developer docs, probably because I'm confused about what I'm seeking... I simply want to send a message to the controller for the custom view to redraw the view right after the data is prepared in the table at the time of launch. Is there a delegate method for one of the core data components that listens for notifications of when data is prepared? Where would this be, in the managedObjectContext?
 
Took me a while to figure this out. I had to trick the NSArrayController into loading data before it normally would, from within applicationDidFinishLoading: and then use that to send the appropriate message. The relevant documentation is here: http://developer.apple.com/library/mac/ ... dings.html

Automatically Prepares Content Flag

If the "automatically prepares content" flag (see, for example, setAutomaticallyPreparesContent:) is set for a controller, the controller's initial content is fetched from its managed object context using the controller's current fetch predicate. It is important to note that the controller's fetch is executed as a delayed operation performed after its managed object context is set (by nib loading)—this therefore happens after awakeFromNib and windowControllerDidLoadNib:. This can create a problem if you want to perform an operation with the contents of an object controller in either of these methods, since the controller's content is nil. You can work around this by executing the fetch "manually" with fetchWithRequest:merge:error:. You pass nil as the fetch request argument to use the default request, as illustrated in the following code fragment.
 
Status
Not open for further replies.