iKiR
iKiR

Reputation: 860

UISlider, thumb do not move

I have slider in my table's cell, here is my slider initialization code:

UISlider* slider = [[UISlider alloc] init];
slider.continuous = NO;

slider.maximumValue = 2;
slider.minimumValue = 0.5f;
slider.value = 0.5f;

...
//put slider into cell

And I can not move this slider's thumb. Why? Please, tell me what I do wrong?

UPDATE: if set slider's initial value to 0.500001f - it works!

Upvotes: 5

Views: 5845

Answers (3)

Felecia Genet
Felecia Genet

Reputation: 367

Make sure that your maximum slider value is set to > 0

Upvotes: 0

Valar Morghulis
Valar Morghulis

Reputation: 687

Not enough code here to estimate the problem. But I recently had the same issue, so I just tell you what's my issue and hope it helps.

Basically I just separate the cell into different regions, with different labels and views. I found out if I add the slider as a subview to the UILabel object, the slider will not move. So I first add a UIView to the same region, then add both the UILabel and the UIslider to this UIView. Now everything works.

Upvotes: 0

Jonathan Starr
Jonathan Starr

Reputation: 254

I doubt that this is directly relevant to this question, but I had a similar problem - my slider could have its value set by my program and it would move, but I could not drag and move it. It turned out that I had coded a trackRectForBounds method for my slider subclass, without realizing that the (x,y) position in this method is relative to the UIView that IS the slider - not the containing view. So I used the same CGRect for the track bounds as I did for the slider in initWithFrame. This put the slider track outside of the slider view. The result was that the slider thumb could not be dragged, and any click in the track OR the slider's view was handled by the containing view.

If I had not happened to give the slider's view a distinct background color, it would not have been clear that the track was outside the view, and I don't know how I would have solved it.

When I changed the (x,y) in trackRectForBounds to (0, 0), OR removed the override trackRectForBounds altogether, everything worked perfectly.

Maybe this post will help someone else.

Upvotes: 2

Related Questions