繁体   English   中英

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

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

我有一个从UITableViewController扩展的Swift类。 它有这个功能

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

有必要,我需要在一个地方以编程方式调用此函数

self.tableView(tableView, cellForRowAt: 1)
  • 我明白了, 不能调用非函数类型'UITableView!'的值

如何以编程方式调用此函数?

您不需要(您不应该)直接调用该委托/数据源方法。 UITableView有一个功能:

tableView.cellForRow(at: indexPath)

只需根据您的行创建索引路径,例如:

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

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