Reputation: 3892
I have a UITableViewController implementing custom cells via
CustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
and in the CustomTableViewCell.h
file I declared
@property (nonatomic, weak) IBOutlet UISlider *slider;
which is connected to my slider in my storyboard and an IBAction
that changes the background of the cell when the slider is adjusted (value changed). My problem is that when I slide down the table view, as soon as my cell is dequeued it is reused with the slider in the same position, and therefore the background an adjusted color. I don't want to keep the entire table in memory, but I need to keep the information input into a cell available for future use. Is there a standard way to handle a problem like this? Thanks.
Upvotes: 0
Views: 608
Reputation: 4218
why not configure the cell after method dequeueReusableCellWithIdentifier
cell.backgroundColor = //adjust the color
cell.slider.value = //adjust value
Upvotes: 0
Reputation: 142
Yes you need to store data for the table in memory (for example slider values in NSArray) and in your UITableView datasource method you need to update state of reused cell. UITableView is smart enough not to load cells for whole table, it loads only visible cells. It is the standard way to do it.
Upvotes: 0
Reputation: 740
You can put your slider values into an array, and the dequeueReusableCellWithIdentifier method, you can set the cell slider value from the array
Upvotes: 1