2 Cocoa Method Questions
2 Cocoa Method Questions
- Subject: 2 Cocoa Method Questions
- From: email@hidden
- Date: Wed, 15 May 2002 23:58:47 EDT
This is from an experienced Mac developer, who is a newbie to Cocoa...
1) When creating non-document Edit/preference style window, what is the best
method of handling the User Interface vs Content?
At WWDC, one apple engineer explicitly said that you should load the User
interface when you need them (ie. opening window), and get rid of it when the
window closes. Each window would have it's own Nib file. This makes sense,
until you look at the Apple provided programming examples. Several of the
programming examples load the UI in at startup (window in the mainmenu.nib
file) with the window invisible, and use the controls on the window as
storage for the important data (ex. user defaults). This method keeps the
window around (invisible), and uses the TextField, Sliders and such as
storage for the strings, integers and flags. Opening and closing the window
is really a show and hide window function. The disadvantage to this is the
memory that is being used up for invisible windows.
The alternative to this is loading the windows on the fly (and disposed
when done), but keeping a copy of the important data in separate NSString,
NSNumber, etc. When the window is opened, the current values would be loaded
into the appropriate Controls. When the Controls change, their values would
be handed off to the above mentioned NSString, NSNumber, etc. You can see
this method is more complex (making sure the Controls & NSObjects are in
sync) as well as taking more memory WHEN the Window is open.
Which method would you use?
I am using the example of User Defaults/Preferences for this method, but it
really is talking about any non-document Window that sometimes is open,
sometimes closed, and contains editable application data.
2) When creating new User Interfaces, and controller objects, should you use
Project Builder to write the template of the controller you are creating
(usually subclass of NSObject)? You would then run Interface Builder, and
Read the .h file so that new class is available for Interface Builder to c
reate an Instance of. When you want to add actions and outlets, you add them
by hand to the .h file, and have Interface Builder re-read the file.
OR
Do you use Interface Builder to create a new subclass, add the needed outlets
and actions using the Interface Builder UI, and then create the .h & .m file
needed for this new object? You then load and compiled these new files using
Project Builder.
As you can see, one example using Project Builder to create the .h & .m file,
while the other method uses Interface Builder. The Interface builder method
is better UI, and easier, but you cannot go back to add more outlets/actions,
and keep any changes/additions you have added to code. Using the Project
Builder method also seems to have some problems with setting up .h & .m file
so Project Builder understand them (especially the new features of not using
outlet & id classes, and being able to said a slider outlet is a NSSlider
object).
The books and examples (and tutorials I seen) use both method, but I am not
sure if it is just because some were written 2 years ago, vs. recently.
Any comments?
Thanks!
Steve Sheets
_______________________________________________
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.