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

标签 ios swift uitableview

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

相关文章:

ios - 在 Swift 中子类化 SpriteKit 类

ios - UITableViewCell 内的 UIWebView,检测到链接但不可点击

ios - UITableView:IndexPath.row 超出范围( fatal error )

ios - AVspeechSynthesizer iOS 文本语音

swift - Metal 计算内核中的 Mipmap 采样器(不是顶点或片段着色器)

objective-c - UITableView 由于阴影和边框而滞后

ios - 如何访问 UITableView 以重新加载数据?

ios - 如何将固定的 SCNNode 附加到 ARKit 的 pointOfView?

iphone - SIGTRAP 在 iOS 6.1.3 上选择特定的 UITableViewCell

ios - 希望我的应用程序只能在 iPhone 4 及更高版本上运行,而不能在其他设备上运行