如何使用 Swift 显示从 Viewcontroller B 接收到的值到 Viewcontroller A tableview 自定义单元格文本视图?

杰西奥斯

我的场景,我将值从Viewcontroller Bto传递过来Viewcontroller AViewcontroller A我维护 tableview CustomCell textview(我只使用一行)。在此文本视图中,我需要显示我从Viewcontroller B. 在这里,我正在使用下面的代码。请为我的场景提供一些想法。

class ViewcontrollerB: UIViewController, isAbleToReceiveData  {

    func pass(data: String) {
        print("USER: \(data)")
    }

    .... 
    ....   

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

        let cell = self.tableview.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! CustomCell

        // From TextView Placeholder and Color
        cell.from_textview.text = "Enter your text" // here I need to show received “data” from VC_B.
        cell.from_textview.textColor = UIColor.lightGray

        return cell
    }
}
iOS用户

创建一个可以从任何地方访问的变量 VC_A

var stringReceived: String? = nil

现在在函数中

func pass(data: String) {
        print("USER: \(data)")
        //add the following 
        stringReceived = data
        self.UITableView_name.reloadData()
    }

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

将以下内容从 更改cell.from_textview.text = "Enter your text"cell.from_textview.text = stringReceived!

所以基本上用于reloadData()在接收到数据后刷新 UITableView。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

Related 相关文章

热门标签

归档