Reputation: 6638
Does anybody have a workaround for using a NSStepper
control (many, in fact..) with an Increment set to 0.1 or anything other than integer values w/o calling setIncrement:
on each and every NSStepper
instance?
I've got an editor-like UI that requires steppers to change the values of their attaches NSTextField
instanced by tiny increments.
Setting the increment to a decimal value in Interface Builder (IB) causes it to round it to an integer - although the API accepts a double.
Even entering nothing in the increment field and using a NSStepper
subclass that calls setIncrement:
for all instances setting it to e.g. 0.1 on init
fails as IB apparently still sets the increment to 0 or something after init
was called..
Not sure how it does that, though, as the setIncrement:
override in the subclass isn't called...
Upvotes: 0
Views: 533
Reputation: 18253
If you have a lot of NSStepper
s which differ from the standard one only by the increment, then you could try to subclass NSStepper
and override initWithCoder:
which is the initialiser called when an object is re-created from a nib file.
I tend to consider initWithCoder:
a designated initialiser together with initWithFrame:
, but the docs are little vague on that aspect. Anyway, if you call super
before you set your own properties, it should work and be robust. If you do this sort of trick you could also consider overriding initWithFrame:
to do the same initialization, so you get consistent behaviour across the different ways to instantiate the subclass.
The downside to this approach is that you will not be able to set the increment
in Interface Builder for your custom subclass, so you might want to document it well for posteriority.
Upvotes: 1