about File's Owner and Application

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

  1. Howiieque macrumors regular

    Feb 1, 2009
    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. kainjow Moderator emeritus


    Jun 15, 2000
    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. Howiieque thread starter macrumors regular

    Feb 1, 2009
    it's kind of you to answer my question so many times. thank you very much.:)

Share This Page