我的场景,我将值从Viewcontroller B
to传递过来Viewcontroller A
。在Viewcontroller 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
}
}
创建一个可以从任何地方访问的变量 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] 删除。
我来说两句