I am trying to update a label in a cell outside of
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
by using
let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as! Cell
in another function. However, I keep getting errors. Therefore, I tried to refer to the cell by using let cell = Cell()
, but I get the error unexpectedly found nil
. Lastly, I tried
let cell = tableView.dequeueReusableCellWithIdentifier("cell") as! Cell
that does not return an error, but the label cell.time.text
is not updated.
Use this:
tableView.cellForRow(at: IndexPath(row: row, section: section)) as! CustomCell
If your cell has properties like
@IBOutlet label: UILabel!
you can use this:
tableView.cellForRow(at: IndexPath(row: row, section: section)) as! CustomCell).label.text = "Test123" // smth like this
Hope it helps
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