【问题标题】:Get the value of textLabel in a cell Swift 3获取单元格 Swift 3 中 textLabel 的值
【发布时间】:2017-06-14 11:58:03
【问题描述】:

我有一个 tableview 原型单元,带有一个 textLabel 和一个按钮,我如何使用带有函数的单元格按钮而不是使用 tableView: UITableView, didSelectRowAt indexPath: IndexPath 来获取 cell.textLabel 的值。

【问题讨论】:

  • 向我们展示您的尝试?

标签: swift3 cell tableviewcell func


【解决方案1】:

简单地说,您必须使用数组来显示数据。

点击按钮获取索引路径

var center: CGPoint = sender.center
var rootViewPoint: CGPoint? = sender.superview?.convertPoint(center, to: filterTableView)
var indexPath: IndexPath? = filterTableView.indexPathForRow(at: rootViewPoint)

现在可以通过在数组中传递这个 indexPath 来找到 cell.textLabel 的值,

let string = array[indexPath.row]

【讨论】:

    【解决方案2】:
    let indexPath = IndexPath(item: x, section: 1)
    let cell = tableView.cellForRow(at: indexPath) as? CustomCell
    let text = cell?.textLabel.text
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-02
      • 1970-01-01
      • 2017-02-18
      相关资源
      最近更新 更多