Re: Several Cocoa questions
Re: Several Cocoa questions
- Subject: Re: Several Cocoa questions
- From: email@hidden
- Date: Wed, 27 Feb 2002 13:46:06 -0800
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.
[NSApp terminate:nil] is (approximately) what the Quit menu item is
normally hooked up to do. So that would make your Off button do the
same thing.
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?
You want to be making an NSDocument-based application, by the sound of
it. I would read about NSDocument in the doc and look at the code for
the TextEdit example application (/Developer/Examples/AppKit/TextEdit).
I don't know whether there's a smaller & simpler example of a
document-based app.
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?
Normally, you'd let the user decide that they want to quit the
program, rather than automatically quitting for them when the last
window is closed. However, the NSApplication delegate method
applicationShouldTerminateAfterLastWindowClosed: will let you do what
you want, if you really want to do it. (This delegate method is left
over from the days of Cocoa on Windows, where this was standard
behavior, I believe). You can read more about NSApp's delegate methods
in the NSApplication doc. There has also been a lot of chat very
recently on this list about how to set up an NSApplication delegate, you
might want to go back and find those posts.
Good luck!
Ben Haller
Stick Software
_______________________________________________
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.