Re: applicationShouldTerminateAfterLastWindowClosed Document-based Project Help?
Re: applicationShouldTerminateAfterLastWindowClosed Document-based Project Help?
- Subject: Re: applicationShouldTerminateAfterLastWindowClosed Document-based Project Help?
- From: Quincey Morris <email@hidden>
- Date: Tue, 23 Mar 2010 10:27:50 -0700
On Mar 23, 2010, at 09:15, Bill Hernandez wrote:
> If I do the following:
>
> ( 1 ) create a NON-document based Cocoa Project:
> ( 2 ) add a button to the nib window, name it DONE
> ( 3 ) Control Click and Drag from DONE to the Window and select performClose: from the HUD
> ( 4 ) Run and click on DONE and applicationShouldTerminateAfterLastWindowClosed gets called, and the app quits just like it is supposed to. So this brief amount of code works GOOD ...
>
> But if I try to get this to work with a Document based Project I cannot get applicationShouldTerminateAfterLastWindowClosed to trigger such that the application will quit.
>
> I have tried creating an AppController Class (SubClass of NSController) then dragged it to the Nib Window, auto-created the AppController methods, and put the code there, and IB will not let me Control-Click-Drag from the File's Owner to the AppController instance in the Nib. The AppController won't highlight. So obviously I am doing something wrong...
>
> [snip]
>
> When I tried this awakeFromNib in MyDocument Class I still could not get applicationShouldTerminateAfterLastWindowClosed to trigger.
>
> [snip]
There's quite a lot of flailing going on here. If something goes wrong, randomly trying to solve a different problem isn't a great strategy.
You have an IB *usability* problem. That is, you tried to do something in IB and it didn't behave as expected. [As a consequence, your application has no delegate, and therefore -- of course -- the application delegate method applicationShouldTerminateAfterLastWindowClosed doesn't get called.]
So, back to IB. You don't say *which* nib you added your AppController instance to. My guess is that you're trying to do this in a document window nib (where File's Owner is of type NSDocument or NSWindowController) instead of the main menu nib. If that's not it, then what is the class of File's Owner? If you select File's Owner and display the Connections tab of the IB inspector, can you drag from the circle next to the 'delegate' outlet to your AppController object? To any object at all?
Also, this is not what you were asking about, and really none of my business, but why on earth do you want a document-based app to close after its last window closes? It denies the user the opportunity to open or create a new document.
Also, regarding your original non-document-based project, even if it was just a throw-away exercise, don't label your button "DONE". I mean this is torturing kittens, or worse. Mac buttons (except for "OK") aren't in uppercase, and the button label should say what it's going to do. "Quit" would have been perfect for this application, I suspect, and just as easy for you to type. :)
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden