On Jan 27, 2011, at 05:54, Bruce Cresanta wrote: > I am trying to open an NSDocument based window. My NSDocument class > follows the standard (MyDocument) class created using the automatic project > settings. I do initialization in the awakeFromNib override within > MyDocument. > > To create the document I use: > > id myDocument = [[NSDocumentController sharedDocumentController] > makeUntitledDocumentOfType:@"DocumentType" error:&error]; > > The awakeFromNib initializations ARE SKIPPED in this call. > > > Does anyone know a way to initialize NSDocument other than in awakeFromNib (I > have nib related bindings)? > > or > > Does anyone know a way to instantiate the NSDocument such that awakeFromNib > is called?
An object will receive an 'awakeFromNib' message if it's unarchived from a NIB file (e.g. views, controls), *or* if it's the File's Owner object for a loaded NIB file. My guess is that your project either has the window in MainMenu.nib, or in a separate file with a NSWindowController as File's Owner. In neither case will 'awakeFromNib' be called for the document. You can read about this in: http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/ApplicationKit/Protocols/NSNibAwaking_Protocol/Reference/Reference.html though I guess it's slightly incomplete. It talks about 'awakeFromNib' being called for File's Owner, and it also talks about 'awakeFromNib' being called for objects in the NIB file, but that usually *doesn't* include File's Owner. That inconsistency looks like a small doc bug. Initializations specific to a document are typically done in 'readFrom...' (opening an existing document) or 'initWithType:' (creating a new document). If you have things to do after NIB loading, you're really talking about something window-related, so you might need to move them to a window controller's 'awakeFromNib' -- or, more likely, 'windowDidLoad' -- or fix a misconfiguration in your NIB. _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com