问题
Ive got a table. each table has its own custom button. when its pressed the following funtion runs
@IBAction func select(sender: UIButton) {
anobject.itsproperty[the row?] = true
}
how do I access which row the button was pressed from? so i can use that to access an array.
回答1:
In cellForRowAtIndexPathassign the row index to the tag property of the button.
cell.button.tag = indexPath.row
then get the tag to distinguish the rows
@IBAction func select(sender: UIButton) {
if sender.tag == 0 {
// do something with first row
}
}
来源:https://stackoverflow.com/questions/31401834/swift-how-to-get-row-number-of-a-button-in-each-table-row