On Jun 20, 2008, at 6:48 AM, Jason Wiggins wrote:
Hi everyone,
<snip>
Any help would be greatly appreciated.
Jason
Some pointers,
1) As has been stated already you don't need the View object at all.
In this case the Window holds your view (if you look at the Nib in
outline mode and open the content triangle for the Window object you
will see that it has a Content View which holds your NSButton and
NSPopUpButton).
2) You don't need the Model object in the NIB. The Controller object
creates a model instance in it's -awakeFromNib method. The objects you
add to the Nib are instantiated when the Nib is loaded so there ends
up being two Model objects and the one in the Nib is just wasting
memory since nothing else refers to it.
With the exception of the first three items (File's Owner, First
Responder and Application) the objects in the Nib are objects that
will be created when it loads. In your example the MainMenu, Window,
Font Manager and your Controller are all objects that are instantiated
when the app runs. You don't need to add objects/classes to the Nib
just because they are in your app, only if you need/want to have them
created for you. The Controller should be in the Nib in this case, you
need it to be created in order to create the Model object and to
interact with the view objects already in the Nib.
3) You should add a dealloc method to your Model object, it should
release the dataString ivar. Read up on memory managment:
http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/Concepts/ObjectOwnership.html#/
/apple_ref/doc/uid/20000043
In other memory management issues, the setDataString: method of Model
needs to properly release the old string object before overwriting
with the new string, otherwise you are leaking memory by not releasing
the old string (you should check that the new string is not the same
string object as the old one first). Read up on accessor methods:
http://developer.apple.com/documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmAccessorMethods.html#/
/apple_ref/doc/uid/TP40003539
4) Just some things to think about/try. You don't need the button to
read the popup's value, you can set an action to the NSPopUpButton in
the same way that you did for the NSButton, then when the user selects
an item the method is called right then. Try creating a new IBAction
method for the popup and in it set a different value to the dataString
of modelInstance for each menu item in the popup. This more directly
models the behavior of a controller, that is it changes the model
based on user input. Maybe add an NSTextField to the window and when
the Model changes it's dataString it tells the Controller which then
updates the text field. Now you have a controller changing the view
based on changes in the model.
Good luck and have fun :)
--Nathan
_______________________________________________
Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com
This email sent to [EMAIL PROTECTED]