[英]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)
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.