Swift: How to get row number of a button in each table row?

安稳与你 提交于 2019-12-13 09:54:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!