Cannot invoke value of non-functional type: UITableView

I have a Swift class that extends from a UITableViewController . It has this function.

 override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {...} 

Needed, I need to call this function programmatically in one place and when I write

 self.tableView(tableView, cellForRowAt: 1) 
  • I get, I can not call the value of the non-function type "UITableView!"

How can I call this function programmatically?

+5
source share
2 answers

You do not need (you should not) access this delegate / datasource method directly. UITableView has a function for this:

 tableView.cellForRow(at: indexPath) 

Just create an index path based on your string, for example:

 let indexPath = IndexPath(row: 1, section: 0) 
+6
source

cellForRowAt accepts an IndexPath , not an Int :

 func someFunc(indexPath: IndexPath) { let cell = tableView(tableView, cellForRowAt: indexPath) print(cell) } 
+1
source

Source: https://habr.com/ru/post/1264010/


All Articles