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.
Asked
Active
Viewed 2,079 times
-2
-
see this http://stackoverflow.com/questions/31649220/detect-button-click-in-table-view-ios-xcode-for-multiple-row-and-section/31649321#31649321 – Anbu.Karthik Feb 21 '17 at 10:03
-
You want multiple selection or single selection for button. – Nirav D Feb 21 '17 at 10:05
-
I will use multiple selection button. – Travis Feb 21 '17 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 – Fahad Jamal Feb 21 '17 at 10:12
2 Answers
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,338
- 1
- 18
- 30
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,242
- 10
- 25