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)applicationShouldTerminateNSApplication *)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?
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)applicationShouldTerminateNSApplication *)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?