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.
4
- see this stackoverflow.com/questions/31649220/…Anbu.Karthik– Anbu.Karthik2017-02-21 10:03:53 +00:00Commented Feb 21, 2017 at 10:03
- You want multiple selection or single selection for button.Nirav D– Nirav D2017-02-21 10:05:14 +00:00Commented Feb 21, 2017 at 10:05
- I will use multiple selection button.Travis– Travis2017-02-21 10:07:03 +00:00Commented 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 methodFahad Jamal– Fahad Jamal2017-02-21 10:12:19 +00:00Commented Feb 21, 2017 at 10:12
Add a comment |
2 Answers
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){ } } 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
Travis
Is this Swift 3 version code? In my case it doesn't worked.
