PDA

View Full Version : about File's Owner and Application




Howiieque
Feb 9, 2009, 10:29 PM
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
Feb 9, 2009, 11:47 PM
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
Feb 10, 2009, 01:50 AM
it's kind of you to answer my question so many times. thank you very much.:)