How to detect tableView cell touched or clicked in swift

后端 未结 9 876
灰色年华
灰色年华 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:37

    I screw up on the every time! Just make sure the tableView delegate and dataSource are declared in viewDidLoad. Then I normally populate a few arrays to simulate returned data and then take it from there!

    //******** Populate Table with data ***********
    public func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{
    
        let cell = tableView.dequeueReusableCell(withIdentifier: "Cell") as? SetupCellView
        cell?.ControllerLbl.text = ViewContHeading[indexPath.row]
        cell?.DetailLbl.text = ViewContDetail[indexPath.row]
        cell?.StartupImageImg.image = UIImage(named: ViewContImages[indexPath.row])
        return cell!
    }
    

提交回复
热议问题