NMRangeSlider icon indicating copy to clipboard operation
NMRangeSlider copied to clipboard

Bug when setting lower and upper bounds in a specific order

Open fmaylinch opened this issue 9 years ago • 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

fmaylinch avatar Nov 04 '15 17:11 fmaylinch

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.

astanton avatar Nov 07 '15 01:11 astanton

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

muZZkat avatar Nov 07 '15 01:11 muZZkat

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 :)

p-antonelli avatar Dec 15 '15 14:12 p-antonelli

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)

luantlai avatar Dec 24 '15 10:12 luantlai

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

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

sreid768 avatar Feb 16 '16 03:02 sreid768

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

Mov1s avatar Apr 12 '16 20:04 Mov1s

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

sreid768 avatar Apr 12 '16 23:04 sreid768