dan martin dan martin - 1 month ago 7x
iOS Question

Swift - UITableview: How to make a tap on one cell cause change a label in another cell?

I have a UITableView, and I'd like a tap in cell X to cause the label text in cell Y to change from "Waiting..." to "Done". I'm pretty baffled as to how I should go about this. I've tried to do this using

, but seemingly I can only modify properties of the cell at the row tapped on.



Its quite easy to get a cell you need to change, but you have to know which row of your table it is:

class MyCell : UITableViewCell {

    @IBOutlet weak var myLabel: UILabel!


class TableViewController: UITableViewController {


    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

        let row = 7 //or what you set
        let cellWhereIsTheLabel = tableView.cellForRow(at: IndexPath(row: row, section: 0)) as! MyCell
        cellWhereIsTheLabel.myLabel.text = "Done"