简体   繁体   English

无法调用非函数类型的值:UITableView

[英]Cannot call value of non-function type: UITableView

I've a Swift class that extends from UITableViewController . 我有一个从UITableViewController扩展的Swift类。 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!' 我明白了, 不能调用非函数类型'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: UITableView有一个功能:

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 : cellForRowAt采用IndexPath而不是Int

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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