簡體   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