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