[英]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有一个功能:
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.