I'm using a "Static Cells" table view created in my storyboard file. However I'd like to update the text on one of these cells when a setting is changed.
I'm pushing a view controller which updates the setting. I'm trying to use a callback to change the cell's text when it's popped off the stack, but by that point the cell has apparently been recycled or reused, so the old object is off screen and no longer used in the table view.
Is there a way I can update this text, and make it permanent (so that when the cell is scrolled off screen and comes back, the new value still appears)?
Assuming your table view hierarchy is along the lines of:
Table View (static cells)
- Table View Section
- Table View Cell
- UILabel (with the text property you want to modify)
UILabel
in your code, and wire it up in the storyboard's UILabel
in the table view hierarchy above.UILabel
's text property as you see fit.You can store text that you want to change as a property and use it in:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = super.tableView(tableView, cellForRowAtIndexPath: indexPath)
switch (indexPath.section, indexPath.row) {
case (0, 3):
cell.textLabel?.text = yourProperty
default: break
}
return cell
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With