-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

4
  • see this stackoverflow.com/questions/31649220/… Commented Feb 21, 2017 at 10:03
  • You want multiple selection or single selection for button. Commented Feb 21, 2017 at 10:05
  • I will use multiple selection button. Commented Feb 21, 2017 at 10:07
  • you should create a custom uitableviewcell and inside that you should add button and create a delegate inside the tablecell and when button is tapped, call that delegate method Commented Feb 21, 2017 at 10:12

2 Answers 2

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){ } } 
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you very much!. It's worked!
No problem 😊 Travis
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 } 

1 Comment

Is this Swift 3 version code? In my case it doesn't worked.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.