gpt4 book ai didi

ios - 快速获取自定义单元格中的 UITextView 数据

转载 作者:搜寻专家 更新时间:2023-11-01 06:05:26 25 4
gpt4 key购买 nike

我有一个自定义单元格,里面有一个 UITextView 和那个 UITextViewoutlet/strong> 在 customCell 文件中。

现在在我的 viewController 中,我有 tableView,我创建自定义单元格并将其添加到我的表格中。在此之后,我无法访问 UITextView 并在 customCell 文件中将其数据作为其 outlet 获取。我无法将 socket 移动到我的 viewController,因为我需要它。我该怎么做(在我的 viewController 中访问 UITextView)

最佳答案

您可以使用 viewController 设置单元格 textView 的委托(delegate),首先在您的 cellForRowAtIndexPath 中设置它的委托(delegate)

func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell!  {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell") as! CustomTableCell
cell.textView.delegate = self
cell.textView.tag = indexPath.row //In case you have multiple textView
return cell
}

现在您可以在其 UITextViewDelegate 方法中获取此 textView。

func textViewDidBeginEditing(textView: UITextView) {
print(textView.text)
}

关于ios - 快速获取自定义单元格中的 UITextView 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38791462/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com