How to get data from different table cell

28 views Asked by At

I have the following code which will trigger when the the didSelectRowAt is called. Which is basically when you click on any row.

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

    if(indexPath.section == 0){
        let indexPath = tableView.indexPathForSelectedRow 
        let currentCell = tableView.cellForRow(at: indexPath!) as! addNameTableViewCell

        print(currentCell.addNameTextField.text)
    }

}

My problem is that I have four sections and in section zero is an button that when pressed I want to be able to return the data that is in section three.

    let indexPath = tableView.indexPathForSelectedRow 

So basically the problem is how to make this instead of the indexPath of the selected row, I want to be able to point it at a different indexPath.

EDIT:

         let indexArray = tableView.indexPathsForVisibleRows

        let currentCell = tableView.cellForRow(at: (indexArray?[1])!) as! addNameTableViewCell

I was able to solve it with the above but still be nice if a better way

0

There are 0 answers