Voripteth
Voripteth

Reputation: 101

UISlider Update inside UITableViewCell

I have a custom UITableViewCell that contains a UISlider control and a UILabel which shows the current text value for the slider position. I want to update the label as the slider knob is dragged. Here are the basic elements.

cellForRowAtIndexPath: This routine takes data and updates the slider value and the label associated with it.

sliderValueChanged: This routine reads the slider value updates the data. It then calls [table reloadData] so the label gets updated.

Problem: Somehow the reloadData is interrupting the flow of updates. If I substitute NSLog instead of reloadData I get a nice stream of updates showing the value of the slider. In an attempt to prevent looping I put in tests to not set the slider value or call reloadData unless the value was different. That didn't fix things.

Any help would be greatly appreciated!

Upvotes: 4

Views: 3265

Answers (2)

Voripteth
Voripteth

Reputation: 101

The problem is being caused by the [table reloadData] which appears to be creating a new Cell object so updates the same slider aren't working. The correct implementation was to get the referenced cell inside the sliderValueChanged routine and set the label from there. Set a tag to the slider to indicate the row and then call the method to get the cell with the index path.

Upvotes: 6

Mr Guy 4
Mr Guy 4

Reputation:

Stuff like this happened to me. Go to build settings and look for a compiler flagged called "Enable floating point library calls". Make sure it's disabled. See if that helps you.

Upvotes: 1

Related Questions