How to detect tableView cell touched or clicked in swift

后端 未结 9 883
灰色年华
灰色年华 2020-12-07 21:46

I\'m trying to get index of selected item in TableView and start some activity after that. Unfortunately most of solutions that I found are in obje

9条回答
  •  死守一世寂寞
    2020-12-07 22:22

    Inherit the tableview delegate and datasource. Implement delegates what you need.

        override func viewDidLoad() {
            super.viewDidLoad()
            tableView.delegate = self
            tableView.dataSource = self
        }
    

    And Finally implement this delegate

         func tableView(_ tableView: UITableView, didSelectRowAt  
         indexPath: IndexPath) {
         print("row selected : \(indexPath.row)")
      }
    

提交回复
热议问题