Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot call value of non-function type: UITableView

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)
  • I get, Cannot call value of non-function type 'UITableView!'

How can I call this function programatically?

like image 709
prabodhprakash Avatar asked Feb 09 '17 08:02

prabodhprakash


2 Answers

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)
like image 144
James Chen Avatar answered Nov 08 '22 23:11

James Chen


cellForRowAt takes an IndexPath, not an Int:

func someFunc(indexPath: IndexPath) {
    let cell = tableView(tableView, cellForRowAt: indexPath)
    print(cell)
}
like image 31
Ashley Mills Avatar answered Nov 09 '22 01:11

Ashley Mills