-2

I can select row using the "didSelectRowAt" function in tableview of swift 3. But how do I do other actions when I select a button in a row? I do not know how to select a button in the tableview.

image

Travis
  • 39
  • 11

2 Answers2

0

Create custom cell
Write below code inside cellForRowAt indexPath of UItableview Method

cell.buttonname?.addTarget(self, action: #selector(self.buttonmethod), for: .touchUpInside)
cell.buttonname.tag = indexPath.section

// Button Clicked Method

func buttonmethod(_ button: UIButton) {
     print(button.tag)
     // perform some action
}
iParesh
  • 2,130
  • 1
  • 15
  • 29
0

Create an outlet action: And find the indexpath using this code

    @IBAction func memberPicTapped(_ sender:UIButton) {
            var superView = sender.superview
            while !(superView is UITableViewCell) {
                superView = superView?.superview
            }
            let cell = superView as! UITableViewCell
            if let indexpath = YourTableView.indexPath(for: cell){

            }
      }
Anuraj
  • 1,232
  • 9
  • 24