在自定义单元格按钮操作中获取节号 [英] Get section number in custom cell button action

查看:68
本文介绍了在自定义单元格按钮操作中获取节号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个tableView动态地在几个部分中填充了自定义单元格.

I have a tableView dynamically populated with custom cells in several sections.

在我的CustomCell类中,对于单元格中的自定义复选框按钮,我有一个@IBAction.有没有办法在IBAction函数中获取发送方按钮的段号?

In my CustomCell class I have an @IBAction for a custom checkbox button in the cell. Is there a way to get the section number of the sender button in the IBAction function?

类似的东西:

@IBAction func checkboxButton(sender: CheckBox) {
    //Change Button state
    if sender.isChecked == true { sender.isChecked = false }
    else { sender.isChecked = true }

    //Get section number of clicked button
    var sectionNumber = ???????

}

推荐答案

其中一种方法,假设您在单元格中有自定义单元格和按钮... 通常的模式是: (如果您正在使用带有数据源的表格视图)在配置内部单元格时:

One of the ways, suppose you have custom cell and button inside a cell ... Usual pattern would be: (if you're using table view with datasource) when configuring the cell inside:

- (UITableViewCell *)tableView:(UITableView *)tableView
     cellForRowAtIndexPath:(NSIndexPath *)indexPath

您可以设置:

cell.button.tag = sectionIndex

所以在

func checkboxButton(sender: CheckBox) { ...

sender.tag将是sectionIndex

sender.tag would be sectionIndex

希望你有个主意.

这篇关于在自定义单元格按钮操作中获取节号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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