Re: How to join two controls together?
Re: How to join two controls together?
- Subject: Re: How to join two controls together?
- From: David Watanabe <email@hidden>
- Date: Sun, 4 Nov 2001 16:13:14 -0800
On Saturday, November 3, 2001, at 03:18 AM, email@hidden wrote:
But this doesn't look like the "right" way. I would like to have them
behave as a unique control (which they rreally are). This is rather
important for me, because I have a lot of such pairs in my app. For
each pair I need two outlets in the controller, and the action is more
complicated.
Here are the difficult things (for me). I just don't know how to do
that. Sure I can subclass NSControl, or NSTextField (though this one
it's difficult), but how to have the stepper drawn and working as
expected? And would it be possible to have IB handle the connections
for this object?
I suspect the easiest way to do this is to subclass NSView (NSControl
might also work, but I'm not certain the requisite methods work) and
simply add the two controllers to the view in the initWithFrame: method
(using addSubview:). You can also define the resizing masks of the two
controls programmatically, as you would in IB. You can then set up the
interaction between the two (pretty easy -- setTarget: and setAction:).
Finally, to make the composite control behave as you wish, just add the
custom methods you are wanting to expose (most of which will just map
down to the two contained controls).
You only need to be vaguely familiar with the drawing hierarchy, since
NSView should take care of subview drawing for you. This whole exercise
is akin to grouping two controls in a box in IB, setting their
attributes & connections. This goes further since you can add custom
methods to control the composition itself as if it were an atomic unit.
Dave Watanabe
sciforums.com | webfansite.com | xlife.org