Search code examples
swift3celluitableviewfunc

Get the value of textLabel in a cell Swift 3


I have a tableview prototypecells, with a textLabel and a button, how can I get the value of the cell.textLabel using the cell button with a function instead of using tableView: UITableView, didSelectRowAt indexPath: IndexPath.


Solution

  • Simply , you must be using an array for displaying data.

    On button click get indexpath using

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

    Now value of the cell.textLabel can be found by passing this indexPath in array as,

    let string = array[indexPath.row]