Change textlabel in static cells in UITableView
I needed this.
dispatch_async(dispatch_get_main_queue(), ^{
(...textLabel updates)
[self.tableView reloadData];
});
Create a property for each cell you want to change in your table view controller, like so:
@property (weak) IBOutlet UITableViewCell *cell1;
@property (weak) IBOutlet UITableViewCell *cell2;
Connect each one to a cell in Interface Builder.
When you only need to change the label's text, you can use
self.cell1.textLabel.text = @"New Text";
If you need to replace the whole label, use
UILabel *newLabel = [[UILabel alloc] init];
self.cell2.textLabel = newLabel;
@RossPenman has posted a good answer.
@ggrana noted a potential issue to do with memory and cell reuse, however don't worry about that ...
For a UITableView
with Static cells all the cells are instantiated up front, before viewDidLoad
is called on your UITableViewController
and aren't reused in the way that dynamic cells are. As such you can even just take IBOutlets
directly to the UITextFields
, UISwitches
, UILabels
and things you are really interested in that you have dropped into you static cells in the Storyboard.