开发者

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, 开发者_如何学Ctell me what I do wrong?

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


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.


If your thumb does not activate the slider, it is most likely because there is a UIView above it. Please post your code for cellForRowAtIndexPath


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜