简体   繁体   中英

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?

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)
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM