문제

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)
  1. Declare an IBOutlet UILabel in your code, and wire it up in the storyboard's UILabel in the table view hierarchy above.
  2. In your callback method, set your 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
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top