PDA

View Full Version : Application termination delegate method




mathcolo
Aug 6, 2009, 12:10 PM
Hi there :D

In my application, I have a class. It's just a class that does some other stuff, but along with that other stuff, I need it to respond as the application delegate to the applicationWillTerminate or applicationShouldTerminate methods. Unfortunately, even after having set the application delegate via. code and Interface Builder, neither one of those methods work.

I'm setting the application delegate in the awakeFromNib method of this class like this:

[[NSApplication sharedApplication] setDelegate:self];

And I'm using the methods like this:


- (void)applicationShouldTerminate:(NSNotification *)aNotification {
NSLog(@"It'd be great if this actually ran...");
}


Also, that method was placed in the header file. I don't know if that matters or not.

Any help would be appreciated! Thanks.



kainjow
Aug 6, 2009, 01:47 PM
And I'm using the methods like this:


- (void)applicationShouldTerminate:(NSNotification *)aNotification {
NSLog(@"It'd be great if this actually ran...");
}

That's the wrong method implementation. While it might still get called, it's wrong. The correct one is this:
- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender

Also, that method was placed in the header file. I don't know if that matters or not.
Most likely you put it in the wrong place. It should go where all your other methods go..

mathcolo
Aug 6, 2009, 02:14 PM
I sincerely apologize for not realizing that the class where this is all in is instantiated in another nib, and not the main one. Therefore, it doesn't get run until another window is shown. I never opened that window while I was testing this.

My bad, but still thanks for your assistance kainjow!