I've a Swift class that extends from UITableViewController
. It has this function
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {...}
There's need that, I need to call this function programatically at one place and when I write
self.tableView(tableView, cellForRowAt: 1)
How can I call this function programatically?
You don't need to (you're not supposed to) call that delegate/datasource method directly. UITableView has a func for that:
tableView.cellForRow(at: indexPath)
Just create the index path based on your row, like:
let indexPath = IndexPath(row: 1, section: 0)
cellForRowAt
takes an IndexPath
, not an Int
:
func someFunc(indexPath: IndexPath) {
let cell = tableView(tableView, cellForRowAt: indexPath)
print(cell)
}
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