How to refer to a cell outside of cellForRowAtIndexPath

Do not use dequeueReusableCellWithIdentifier outside the cellForRowAtIndexPath method.

You should use cellForRow(at:) https://developer.apple.com/reference/uikit/uitableview/1614983-cellforrow


Swift 3.0 & Swift 4

let indexPath = IndexPath(row: 0, section: 0)
let cell = tableView.cellForRow(at: indexPath)

Swift 2.3

let indexPath = NSIndexPath(forRow: 0, inSection: 0)
let cell = tableView.cellForRowAtIndexPath(indexPath)

NOTE :- With help of above method you can only get visible cell of tableView except cell is nil


If you want to use cell outside of the UITableView override method cellForRowAt indexPath then first of all, you need to fetch the indexPath of row and then using the indexPath of that row you can get the cell of UITableView.

Once, you get the cell then you can access their properties & methods outside of UITableView.

Try this:

In this code, i'm use a Custom Cell.

let indexPath = IndexPath.init(row: 0, section: 0)
let cell = tableView.cellForRow(at: indexPath) as! MembersCell

Step1:

update the data of the model

Step2:

reload indexPath

 let indexPathToRefresh = IndexPath(row: 0, section: 0)
 tableView.reloadRows(at: [indexPathToRefresh], with: .none)