SliderText = NSSlider + NSTextField
SliderText = NSSlider + NSTextField
- Subject: SliderText = NSSlider + NSTextField
- From: John Richetta <email@hidden>
- Date: Wed, 30 Jan 2008 15:47:14 -0800
(I found a couple messages in the archive that deal with my question,
but none I found address it directly.)
I'd like to create a unified "SliderText" control, that maintains a
single numeric value, using both a slider and a text field (the
latter providing high precision, when required). Changing either one
should update the other, and notify clients of changes, and actions,
as normal controls would. I'd also like this pairing to be as "self
maintaining" as possible: I don't want the UI controller (window,
panel, etc.), to deal with any messages beyond those it might receive
from a single control. Also, creating one of these in IB should be
no harder than copy/pasting an existing paired control.
(Since I have roughly a hundred of these in my application, with more
to come, it's unacceptable tedium, code duplication, and maintenance
inefficiency to require the UI controller to synchronize these
controls.)
I achieved this readily in PowerPlant, but I'm not entirely sure what
is the best way to do this in Cocoa. It may not require custom code,
but I'm doubtful, presently. I don't think I can get all required
notifications, maintain text field numeric accuracy, and avoid
message loops, without custom code of some kind (sure would be great,
though).
My best guess how to implement this cleanly is to create a new custom
view (not control), and simply use it as a controller, to synchronize
two contained controls. This should avoid message loops. To obtain
the paired "control" value, the UI controller would examine the text
field using doubleValue, etc. I think the view could get away with
forwarding only the slider action messages, and maybe the text
delegate notifications (?).
If I could create a proper control, that supported all the usual
control behavior, I'd much prefer that, but I'm not keen on
implementing any significant control or cell subclass, unless it can
be done quite cleanly (without messing up control/cell interaction,
and preferably without a lot of code). I don't see an easy way to
subclass NSControl, given the need to support a "cell" for the paired
controls. I might be missing something obvious, however. (Maybe a
custom slider "shim" cell could forward messages to its sibling text
cell as well as its own (contained) slider cell...??)
Is implementing a simple custom view a reasonable plan? Can someone
recommend better? Suggestions greatly appreciated.
-jar
_______________________________________________
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