I had posted this message at
http://discussions.apple.com/thread.jspa?threadID=2374717&tstart=0
but thought I might have better luck here.
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...
// TestNoDocAppDelegate.h
// TestNoDoc
#import <Cocoa/Cocoa.h>
@interface TestNoDocAppDelegate : NSObject <NSApplicationDelegate> {
NSWindow *window;
}
@property (assign) IBOutlet NSWindow *window;
@end
// TestNoDocAppDelegate.m
// TestNoDoc
#import "TestNoDocAppDelegate.h"
@implementation TestNoDocAppDelegate
@synthesize window;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Insert code here to initialize your application
}
// If the user closes the last window in the application, make sure the
application quits.
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender
{
NSLog(@"[4567] %@",@"applicationShouldTerminateAfterLastWindowClosed");
return YES;
}
@end
When I tried this awakeFromNib in MyDocument Class I still could not get
applicationShouldTerminateAfterLastWindowClosed to trigger.
- (void) awakeFromNib
{
NSLog(@"[4001] %@",[NSApp delegate]); // returned null
[NSApp setDelegate:self];
[[NSApp delegate]
applicationShouldTerminateAfterLastWindowClosed:NSApp];
// this got called OK
NSLog(@"[4002] %@",[NSApp delegate]);
// returned non-null value (whether it was good or not, I don't know. I
assume it was.)
}
I am missing something with either not having the right class, or probably with
the Nib Window connections.
I'd be grateful for some help.
Bill Hernandez
Plano, Texas
Steve Herman1 wrote:
So, instantiate a DocAppDelegate object in the MainMenu.xib instead. The File's
Owner in that file represents the application so you can control drag from
there to your delegate object.
.
.
I tried this and umpteen different combinations, and finally gave up. I know
there's got to be a way to have the application respond to delegate methods, I
just haven't found anything that shows how to get a document based project to
respond to applicationShouldTerminateAfterLastWindowClosed.
.
.
PS - I tried creating my delegate object in MyDocument.xib and the
control-dragging from the "Application" object to my delegate. That seems to
work in IB and allowed me to make the connection, but when I built and ran the
app it would crash when the last window closed... I'm not sure what the
difference is between that object and the "File's Owner" or the "Application"
object in in MainMenu.xib (both of which worked).
.
I ran into the same crashes. Maybe someone will come up with an answer...
_______________________________________________
Cocoa-dev mailing list ([email protected])
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 [email protected]