In my app, I have a scheduling feature that uses nssteppers to pick the minute/hour/am/pm value. After holding down the mouse button, the steppers move one or two ticks, then freeze, requiring click after click.
Why is this happening? I thought steppers were able to just cycle through number during the mouse down…
Have you enabled “Autorepeats” in the Attributes pane of IB for the stepper? What code do you have connected to the stepper? Does it do anything besides actually just incrementing its own value for reference later or does it drive something else (like each step creates a new folder in the Finder, etc.)?
Here’s the exact code I’m using, called from the onclicked theObject handler, I’ve checked and autorepeats are enabled in the stepper properties in the nib
if name of theObject is "hourStepper" then
set hourval to ((contents of stepper "hourStepper" of tab view item "auto" of tab view "tabs" of window "main") as integer)
if hourval is less than or equal to 9 then
set contents of text field "hourDisplay" of tab view item "auto" of tab view "tabs" of window "main" to "0" & hourval
else if hourval is greater than 9 then
set contents of text field "hourDisplay" of tab view item "auto" of tab view "tabs" of window "main" to hourval
end if
set hourValue to hourval
end if
if name of theObject is "minStepper" then
set minval to ((contents of stepper "minStepper" of tab view item "auto" of tab view "tabs" of window "main") as integer)
if minval is less than or equal to 9 then
set contents of text field "minDisplay" of tab view item "auto" of tab view "tabs" of window "main" to "0" & minval
else if minval is greater than 9 then
set contents of text field "minDisplay" of tab view item "auto" of tab view "tabs" of window "main" to minval
end if
set minValue to minval
end if
if name of theObject is "ampmstepper" then
set ampmval to contents of stepper "ampmstepper" of tab view item "auto" of tab view "tabs" of window "main"
set contents of text field "ampm" of tab view item "auto" of tab view "tabs" of window "main" to ""
if ampmval is equal to 1 then
set contents of text field "ampm" of tab view item "auto" of tab view "tabs" of window "main" to "am"
else if ampmval is equal to 0 then
set contents of text field "ampm" of tab view item "auto" of tab view "tabs" of window "main" to "pm"
end if
set ampmvalue to ampmval
end if
Code optimization will help. In your on clicked handler, use compound if-then-else statements so the script doesn’t have to do so much each time the stepper is clicked. The following code will first test to see if the item clicked is a stepper and, if so, test for each name. Once it successfully passes the if test, then it doesn’t waste time with other tests that obviously will fail. This is the beauty of the compound if-then-else construct. Learn it. Live it. Love it:
on clicked theObject
set objectName to name of theObject
if class of theObject = stepper then
set theVal to integer value of theObject
if objectName = "hourStepper" then
set hourValue to theVal
if theVal ≤ 9 then set theVal to "0" & theVal
set theTextField to "hourDisplay"
else if objectName = "minStepper" then
set minValue to theVal
if theVal ≤ 9 then set theVal to "0" & theVal
set theTextField to "minDisplay"
else if objectName = "ampmstepper" then
set ampmvalue to theVal
if theVal = 1 then
set theVal to "am"
else
set theVal to "pm"
end if
set theTextField to "ampm"
end if
set contents of text field theTextField of tab view item "auto" of tab view "tabs" of window "main" to theVal
else
--code here for non-stepper controls (e.g., regular buttons)
end if
end clicked