1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

about File's Owner and Application

Discussion in 'Mac Programming' started by Howiieque, Feb 9, 2009.

  1. macrumors regular

    #1
    Implement the NSApplication delegate method of applicationShouldTerminate: to display a confirmation dialog box when the user tries to quit the application.

    One way to do this is to make the MyDelegate object instance a delegate of NSApplication and implement the applicationShouldTerminate: method. To do this, Control-drag a connection from File's Owner to MyDelegate in Interface Builder, then add the following method to the MyDelegate class:

    - (NSTerminationReply)applicationShouldTerminate:(NSApplication *)sender
    {
    int answer = NSRunAlertPanel(@"Quit", @"Are you sure?",
    @"Quit", @"Cancel", nil);
    if (answer == NSAlertDefaultReturn) {
    return NSTerminateNow;
    } else {
    return NSTerminateCancel;
    }
    }

    if i make a connection from Application to MyDelegate, things work properly. It seems that they are both NSApplication instance. WHAT is the difference between this two kinds of operation?
     
  2. Moderator emeritus

    kainjow

    #2
    The Application object in the nib is new in Interface Builder 3. It wasn't there in the previous versions, but the File's Owner was always NSApplication (technically, the bundle's Principle Class set in Info.plist). I'm guessing they added the Application object just to make things easier.
     
  3. macrumors regular

    #3
    it's kind of you to answer my question so many times. thank you very much.:)
     

Share This Page