How to detect tableView cell touched or clicked in swift

后端 未结 9 875
灰色年华
灰色年华 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!
    }
    
    0 讨论(0)
  • 2020-12-07 22:38

    Problem was solved by myself using tutorial of weheartswift

    0 讨论(0)
  • 2020-12-07 22:40

    In Swift 3.0

    You can find the event for the touch/click of the cell of tableview through it delegate method. As well, can find the section and row value of the cell like this.

    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
           print("section: \(indexPath.section)")
           print("row: \(indexPath.row)")
    }
    
    0 讨论(0)
提交回复
热议问题