I am instituting a NSSlider into my project that needs to call different methods when moved up or down. So if it is moved up it will do one method, which is a AppleScript, and the opposite if moved in the other direction, another AppleScript. Would I do this with an IF loop or something else? Thanks in advance!
Asked
Active
Viewed 174 times
1 Answers
3
you should keep track of the old value of the slider, and then compare with the new one to see if it has moved down or up.
- (IBAction)slide:(id)sender {
float newValue = [slider floatValue];
if (newValue < oldValue) {
// moved down
} else {
// moved up
}
oldValue = newValue;
}

sch
- 27,436
- 3
- 68
- 83
-
That is great, any idea how to keep track of the value on the slider? – Stevezie Feb 15 '12 at 21:24
-
by using a the global variable **oldValue** mentioned in the code. You initialize it with the initial value of the slider (not shown in the code). And then every time the slider value changes, you update **oldValue** (this is what I did in the line **oldValue = newValue;** – sch Feb 15 '12 at 21:28