applicationShouldOpenUntitledFile is not being called


I’m working with the second edition and hit a problem in Chapter 10.
I’m using Lion and Xcode 4.1
Now that AppController is the delegate for NSApplication, I’m supposed to be getting a call to applicationShouldOpenUntitledFile.
This will make use of the user’s setting in the preferences panel.
But this delegate method is not being called.
I tracked down a discussion of this on another site and it suggested that if the delegate file (AppController) is being instantiated in the nib then this method is not called.
it seems that AppController is instantiated in the nib. So is that why I’m not getting the method ?
Is there a work around ?


It turns out that this method will be called if I have closed the window (all windows) before quitting.
Then the next time I start, because no windows are open, the message is sent to ask whether or not a new one should be opened.
It honors my Boolean return value. Opening or not depending on this value.

So it’s not that the window was instantiated in the nib file. It’s that it was open the last time I ran, that prevents this method from being called. If it was open, it will reopen it without asking whether I want it to or not.

Thanks !


Hi Netsmith,
Interesting to read you comments…
I do get similar problem as you describe, but I can not trace it to the state you mentioned in the last post.

I do have two delegate methods,

  • (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender {
  • (void)applicationDidFinishLaunching:(NSNotification *)aNotification {

The applicationShouldOpenUntitledFile: method is called from time to time, but I really do not when. I was not able to trace it. Since it is very inconsistent I do have a big problem. The logic of opening old documents is placed there and It get mixed up if the method is only some times opened.

I would appreciate some explanation or help.