在Button Swift中通过标签发送行和节 [英] Send Row and Section through Tag in Button Swift

查看:54
本文介绍了在Button Swift中通过标签发送行和节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 cellForRowAtIndexPath

   cell.plusBut.tag = indexPath.row
   cell.plusBut.addTarget(self, action: "plusHit:", forControlEvents: UIControlEvents.TouchUpInside)

和此功能以外的地方:

func plusHit(sender: UIButton!){
    buildings[sender.tag].something = somethingElse
}

是否可以发送 indexPath.row indexPath.section ,或其他替代方法?

Is it possible to send the indexPath.row and indexPath.section, or some alternative??

谢谢!

编辑

我是这样处理的:

我的自定义按钮

class MyButton: UIButton{

    var myRow: Int = 0
    var mySection: Int = 0

}

我的自定义单元格

class NewsCell: UITableViewCell{

    @IBOutlet weak var greenLike: MyButton!

在CellForRowAtIndexPath中

    cell.greenLike.myRow = indexPath.row

我在这条线上出现错误.

I get an error on this line.

推荐答案

您可以创建 UIButton 的子类,并在其中创建一个额外的属性部分.然后,您可以将该类用于单元格按钮.您可以对行执行相同的操作.

You can create a subclass of UIButton and create an extra property section in it. And then you can use that class for cell button. You can do the same for row.

子类化 UIButton

cell.plusBut.tag = indexPath.row
cell.plusBut.section = indexPath.section

cell.plusBut.row = indexPath.row
cell.plusBut.section = indexPath.section

cell.plusBut.indexPath = indexPath

选择任何适合您的方式.

Choose whatever suits you.

这篇关于在Button Swift中通过标签发送行和节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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