Shane
Shane

Reputation: 397

swift - set UILabel without reload of custom UITableViewCell

Is it possible to set a value for a UILabel in a custom UITableViewCell without reloading the cell?

I've tried many permutations of:

let indexPath = NSIndexPath(forRow: 0, inSection: 0)
let cell = tableView.cellForRowAtIndexPath(indexPath) as! CustomTableViewCell1
cell.customLabel.text = "text goes here"

.. and I don't understand why this won't work. I've got a UITextField in the UITableViewCell, and when I set the textField value I'd like only the label to update, but not reload the entire cell. Any suggestions?

Upvotes: 1

Views: 1640

Answers (2)

Alessandro Ornano
Alessandro Ornano

Reputation: 35412

 cell.customLabel.setNeedsDisplay() 

Upvotes: 3

Twitter khuong291
Twitter khuong291

Reputation: 11700

If you want to update the UIViews, you need to put them in main thread:

dispatch_async(dispatch_get_main_queue(),{
   cell.customLabel.text = "text goes here"
})

Upvotes: 2

Related Questions