我有一个自定义单元格,里面有一个 UITextView
和那个 UITextView
的 outlet
/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/