Application termination delegate method

Discussion in 'Mac Programming' started by mathcolo, Aug 6, 2009.

  1. mathcolo macrumors 6502a

    Joined:
    Sep 14, 2008
    Location:
    Massachusetts
    #1
    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:

    Code:
    [[NSApplication sharedApplication] setDelegate:self];
    And I'm using the methods like this:

    Code:
    - (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.
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    That's the wrong method implementation. While it might still get called, it's wrong. The correct one is this:
    Code:
    - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender
    Most likely you put it in the wrong place. It should go where all your other methods go..
     
  3. mathcolo thread starter macrumors 6502a

    Joined:
    Sep 14, 2008
    Location:
    Massachusetts
    #3
    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!
     

Share This Page