Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Howiieque

macrumors regular
Original poster
Feb 1, 2009
120
0
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?
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
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.
 

Howiieque

macrumors regular
Original poster
Feb 1, 2009
120
0
it's kind of you to answer my question so many times. thank you very much.:)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.