Swift:如何获取每个表格行中按钮的行号? [英] Swift: How to get row number of a button in each table row?

查看:34
本文介绍了Swift:如何获取每个表格行中按钮的行号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张桌子.每个表都有自己的自定义按钮.当它按下时运行以下功能

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.

推荐答案

cellForRowAtIndexPath 中将行索引分配给按钮的 tag 属性.

In cellForRowAtIndexPathassign the row index to the tag property of the button.

cell.button.tag = indexPath.row

然后获取标签来区分行

@IBAction func select(sender: UIButton) {
   if sender.tag == 0 {
     // do something with first row
   }
 }

这篇关于Swift:如何获取每个表格行中按钮的行号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆