Re: code for drawing an NSTextField to a panel window ...
Re: code for drawing an NSTextField to a panel window ...
- Subject: Re: code for drawing an NSTextField to a panel window ...
- From: Chris Hanson <email@hidden>
- Date: Thu, 12 Mar 2009 16:55:42 -0700
On Mar 12, 2009, at 4:41 PM, vinai wrote:
The complete code for the object is attached. I guess I am still
more than a little perplexed why the window itself is being drawn
fine, but I can't get any elements (like the text field) drawn to
the panel view.
Glancing at your code, I don't have a solution for your issue but I do
have a strong recommendation: Spend a little time learning the Cocoa
way of doing things before jumping into this project, and follow the
Cocoa way of doing things whenever you can.
The reason I suggest this is that you've started out by following a
classic Cocoa anti-pattern, "window subclassing." That is, your
ControlPanel class is a subclass of NSPanel (which is a subclass of
NSWindow) not because it's a different "kind" of window but just
because it has some controls in it.
If you don't need a window that has significantly different behavior -
a different look, different enable/disable behavior, specialized
handling of first responder, etc. - then you should use an
NSWindowController subclass and a generic NSWindow or NSPanel rather
than your own custom subclass.
You've also followed another well-known Cocoa anti-pattern, "not using
IB," which can be seen from your code not just because you're trying
to instantiate NSTextField objects yourself, but also because there
are no IBOutlet or IBAction annotations in your header file. Unless
you have very specific needs, especially as a developer new to Cocoa
you should do your user interface layout in a nib file in Interface
Builder. (Create it as a xib file, it will be compiled into a runtime
nib file by Xcode.)
The NSWindowController and NSViewController architecture within Cocoa
makes this very straightforward, because you can actually specify the
nib file to associate with a particular window or view controller
instance (or class) and have the instantiated controller act as File's
Owner for the nib. This will save you a lot of trouble writing
tedious code to create views & controls, wire them up, and ensure they
have exactly the look and feel you need.
-- Chris
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden