PDA

View Full Version : Document App: Triggering Behaviour After a New Document




knightlie
Apr 30, 2012, 04:34 AM
I have a Core Data document-based application which is all working correctly. I'd like to implement a "New Document wizard" which appears as a sheet after the user has created a new document - the wizard will ask some questions and populate aspects of the document with the users choices. The wizard is displayed by a method of the document controller class.

I've tried calling the method in a number of places but none of them seem to work. Placing the call in awakeFromNib or windowControllerDidLoadNib: causes an infinite loop.

Does anyone have an idea of the best method to place this call in? I guess I'm looking for some kind of "document has finished being created" method to override, or notification to observe.

Thanks in advance.



thundersteele
Apr 30, 2012, 11:00 AM
Does anyone have an idea of the best method to place this call in? I guess I'm looking for some kind of "document has finished being created" method to override, or notification to observe.


Yes, that is what you need to overwrite. The method that is called only when a new Document is created (and not when an existing one is opened) is - initWithType:error: See the documentation (https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Classes/nsdocument_Class/Reference/Reference.html).

You should also have a look at the basic guide (https://developer.apple.com/library/mac/#documentation/DataManagement/Conceptual/DocBasedAppProgrammingGuideForOSX/Introduction/Introduction.html#//apple_ref/doc/uid/TP40011179) for document based applications, I found it quite useful.

knightlie
Apr 30, 2012, 11:26 AM
Great, that's perfect, thanks.