muZZkat/NMRangeSlider

Bug when setting lower and upper bounds in a specific order

Opened this issue ยท 7 comments

I've seen that there's a bug when setting values like these:

    hourSlider.minimumValue = 6
    hourSlider.maximumValue = 23
    hourSlider.lowerValue = 6
    hourSlider.upperValue = 23

It seems that the setter for lowerValue limits the value to current upperValue(which is 1.0 by default) so lowerValue ends up being 1.0 too. But since the minimumValue is 6 you get a wrong slider.

It works if I set the values in this order:

    hourSlider.maximumValue = 23
    hourSlider.minimumValue = 6
    hourSlider.upperValue = 23
    hourSlider.lowerValue = 6

Thanks a bunch for posting this. I just spent an hour trying to figure out if I was going crazy or not with things working a certain way and not in other instances lol. I did what you said and it's working as expected.

Really surprised this isn't a standard iOS control. This is the best one that I found by far because it is styled to look like the other controls on iOS.

Sorry, I've been meaning to fix this bug for a while!

First, thanks a lot for this useful component, that should have been a standard control in my opinion,
This is just a small bug, but really annoying in my case

I faced the same problem for several hours, going mad trying to reload the cell containing the control in every moment possible.... :(, but hopefully found this solution xD

Special thanks to fmaylinch for finding the good sequence of setting values :)

this bug is at line 139 of NMRangeSlider.m:

value = MIN(value, _upperValue - _minimumRange);

when you set the lowerValue, the default _upperValue has not been set yet, it still 1.0 by default
So I fixed this by calling set value 2 times, the first time should have no animated:

    rangeSlider.setLowerValue(Float(lowerValue), upperValue: Float(upperValue), animated: false)
    rangeSlider.setLowerValue(Float(lowerValue), upperValue: Float(upperValue), animated: false)

I've created a Pull Request that resolves this issue.

Fixed bug when setting lower and upper bounds in a specific order

Mov1s commented

Oh my god, thank you for pointing this out, this caused me a huge headache. Thanks for the control @muZZkat !

Haha no worries. Just waiting for it to be integrated into the master branch. Let me know if it works for you.