Who? What? When?
Thursday, June 28th, 2007I found a problem with the new feature that required a couple of method calls when a new document is loaded. I figured the best place to put these was in the document class in the readFromData:ofType method.
No joy. It turns out the methods I’m calling need data from the sub-classed WindowController object, which hasn’t been instantiated yet. Okay, move the calls to the document’s makeDocumentControllers method, since it looks like the controller has been created and connected by then. Still no joy. I guess this happens asynchronously.
I ended up moving the calls to the windowDidLoad method, in the WindowController sub-class. It’s not as clean as I’d like, since I have to do some checks to see if it’s a brand-new document or a previously-saved document, but it works.
The thing is, this kind of problem has bitten me before. With an AppController, Window Controller, documents, windows, and custom views, I have no idea what happens when. I really need sort of life-cycle chart for the Cocoa document-based app, that tells me which objects are instantiated, and which methods are called, and in what order. Luckily, I don’t (yet?) have a custom NSDocumentController or things could get really messy.
