簡體   English   中英

如何將數據從 ViewController 設置為 UITableView 自定義單元格

[英]How to set data from ViewController to UITableView custom Cell

我一直在嘗試使用自定義委托將數據從 Viewcontroller 傳遞到 UITableView 自定義單元格。有將數據從自定義單元格傳遞到 ViewController 的答案,但反之亦然。誰能建議我一些想法或示例代碼。

我不確定這是否是您的意思,但是您可以在function tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell

例如:

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

        let cell = tableView.dequeueReusableCell(withIdentifier: ViewController.cellIdentifier, for: indexPath) as! CustomCell
        cell.data = data 
        return cell

    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM