Re: Several Cocoa questions
Re: Several Cocoa questions
- Subject: Re: Several Cocoa questions
- From: Eric Peyton <email@hidden>
- Date: Wed, 27 Feb 2002 12:36:57 -0600
On Wednesday, February 27, 2002, at 12:19 PM, Chad Armstrong wrote:
Hello,
I'm fairly new to Cocoa development, and I have several questions which
I hope can make my small application I'm working on, run a little
smoother.
1) Closing the app from a button - If there is an Off or Close button
in the program window, what code is necessary to tell the program to
shut down? In Java, this would be fairly simple with a command like:
System.exit(0);
But I am using just Objective-C Cocoa, no Java.
Read the docs on NSApplication
[NSApp terminate:] or [NSApp stop:] should do what you need (read the
documentation to understand the difference).
2) How can I create multiple instances/windows of my program? Do I
just create a function which allocates a new instance of the program
and that handles most of the problems?
Yes, it's generally easiest to use an NSWindowController (especially
when using NSDocuments), but you can easily write a method that
allocates a new window and during the new window initialization it can
load itself a UI from a nib.
3) When the last window of the program is closed, what code is
necessary to tell the entire program to shut down? Also, how would I
link in this information to my interface, if necessary?
No need to link it into the interface, NSApplication knows what to do.
You will need to add an NSApplication delegate and then have the
delegate respond to
- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication
*)sender;
Once again, read the docs on NSApplication.
Eric
Thanks for any help.
Chad Armstrong
email@hidden
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.