Brad
Brad

Reputation: 705

Why Is my UISlider Thumb Image Being Shown Multiple Times and Not Disappearing As They Should?

This slider is possessed: Slider http://gorgando.com/possessedSlider.jpg

Whenever I enter "editing mode" for the tableview or leave "editing mode" a duplicate thumb image will appear where the thumb is. It is now behaving consistently in this way. If I switch back and forth from editing mode I'll get lots of thumb images like the screenshot shows.

This is the code that I use to create the slider (in the cellForRowAtIndexPath method):

CGRect frame = CGRectMake(20, 42.0, 280.0, 22);
self.slider = [[UISlider alloc] initWithFrame:frame];
[self.slider addTarget:self action:@selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
self.slider.continuous = YES;
self.slider.minimumValue = 0.0;
self.slider.maximumValue = 5.0;
self.slider.value = 0.0;
[[interestCell contentView] addSubview:self.slider];

Appreciate any thoughts you might have!

[I just edited/updated this to reflect the questions/suggestions I received but it's still having problems].

Upvotes: 0

Views: 779

Answers (2)

Brad
Brad

Reputation: 705

Finally figured it out!

I had to move my code to the viewDidLoad method except for setting the slider to the contentView, which happens in the cellForRowAtIndexPath method still. What a strange problem that was. Thanks to those who helped and commented!

Upvotes: 0

coneybeare
coneybeare

Reputation: 33101

Try adding it to the cell's contentView and not the cell itself.

Upvotes: 1

Related Questions