In a tableviewcell I have a UISlider. If I move the slider knob, go back to my previous view, and then return back to the table view, the knob on the slider returned back to zero but I see a “ghosting” of the knob where I had previously moved the slider too.
I clear the context view on the slider object in cellForRowAtIndexPath: and reload the table in viewDidAppear.
Anyone know how to fix this? It’s quite annoying. I put the slider code down below if that helps at all.
// Setup slider
CGRect sliderFrame = CGRectMake(15, 56, 230, 0);
UISlider *slider = [[UISlider alloc] initWithFrame:sliderFrame];
slider.clearsContextBeforeDrawing = YES;
[slider addTarget:self action:@selector(sliderUpdated:) forControlEvents:UIControlEventValueChanged];
[slider addTarget:self action:@selector(sliderStopped:) forControlEvents:UIControlEventTouchUpInside];
[cell.contentView addSubview:slider];
[slider release];
I appreciate it! Thanks!
It is most likely that you are creating a new
UISliderover the oldUISliderwhich gives the ghosting effect.Two possible solutions
Tag the
UISliderwhen you add it to a cell.Subclass
UITableViewCelland add aUISliderto it’s content view and keep a reference to it with an ivar.To do 1 simply tag the
UISliderwhen you add it to the contentView. Then when you get a cell again you try getting the view back first or you create it a fresh.Although 2 is a little more involved it is my preferred method but I am sure there are some great examples of how to do it. There is some great docs by Apple so check them out Table View Programming Guide specifically look at the section
A Closer Look at Table-View Cells