ksa_coder
ksa_coder

Reputation: 1403

iOS - UISlider showing multiple values when sliding

I am using a UISlider in my app and in the UIViewController trying to capture its value.
When I use the slider and change between points on it, I get the below in the terminal :

0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1

I want to make sure I only get 0 or 1 or 2 and not multiple updates as I move.
How can this be done?

Here is the code I have :

@IBAction func sliderMoved(sender: UISlider) {
    sender.setValue(Float(lroundf(self.ladderLengthSlider.value)), animated: true)
    //print(self.ladderLengthSlider.value)
    self.ladderLength = (lroundf(self.ladderLengthSlider.value))
    self.mainObject.ladderLength = Int(ladderLength)
    print(ladderLength)
}

Any idea will be appreciated.
Thanks in advance.

Upvotes: 0

Views: 417

Answers (2)

PlusInfosys
PlusInfosys

Reputation: 3446

You need to store previous value of your slide in global variable. and perform action only when new value is not equal to previous value.

There is no other way.

if sender.value == prevVal
{
return;
}

prevVal = sender.value
...
//perform other task
...

Upvotes: 2

Devang Tandel
Devang Tandel

Reputation: 3008

set slider's

isContinuous = false

Upvotes: 0

Related Questions