Changing text in a static UITableView cell?

I use the "Static Cells" tabular view created in my storyboard file. However, I would like to update the text in one of these cells when changing the settings.

I click on a view controller that updates the setting. I am trying to use a callback to change the text of a cell when it popped out of the stack, but by this point the cell seems to have been recycled or reused, so the old object is disconnected from the screen and is no longer used in the table view.

Is there a way to update this text and make it permanent (so when a cell scrolls from the screen and returns, a new value appears)?

+7
source share
2 answers

Assuming the table presentation hierarchy corresponds to the following lines:

Table View (static cells) - Table View Section - Table View Cell - UILabel (with the text property you want to modify) 
  • Declare the IBOutlet UILabel in your code and plug it in the UILabel storyboard in the table view hierarchy above.
  • In your callback method, set the UILabel text property to your convenience.
+19
source

You can save the text 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 } 
0
source

All Articles