which cell button has pressed in tableView in swift 3

前端 未结 2 1635
悲哀的现实
悲哀的现实 2021-02-11 08:20

I have read similar questions like this but these codes didn\'t worked for me so please help : I have a table view with some buttons in each cells - This table view is factor fo

2条回答
  •  不思量自难忘°
    2021-02-11 08:37

    Create IBAction for you button in the custom cell class then declare a block that will be called on button click.

    var ButtonHandler:(()-> Void)!
    
        @IBAction func ButtonClicked(_ sender: Any) {
                self.ButtonHandler()
            }
    

    Then in your tableview class inside the cell for row method,

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
            let cell = playlistTableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! CustomTableViewCell
            cell.ButtonHandler = {()-> Void in
                // your code 
            }
            return cell
    }
    

提交回复
热议问题