在UITableView中的自定义UITableViewCell中选择子视图

时间:2010-07-12 12:32:56

标签: objective-c iphone uitableview

我有一个由自定义UITableViewCells组成的UITableView,其中包含一些文本和一个按钮。 单元格的allowSelection属性设置为NO,这样我可以点击按钮而不选择单元格。

我正在尝试找到一种方法,以便在按下该单元格的按钮时知道表格中的哪个单元格被点击。有没有办法做到这一点?

非常感谢, 布雷特

1 个答案:

答案 0 :(得分:4)

如果您的UIButtonUITableViewCell[cell addSubview:button];cell.accessoryView = button;

的直接子视图,请使用此选项
- (IBAction)buttonTapped:(id)sender {
    UIButton *button = (UIButton *)sender;
    UITableViewCell *cell = (UITableViewCell *)button.superview;
}

或者,如果您的UIButtonUITableViewCell contentView [cell.contentView addSubview:button];- (IBAction)buttonTapped:(id)sender { UIButton *button = (UIButton *)sender; UITableViewCell *cell = (UITableViewCell *)button.superview.superview; } )的子视图,则

{{1}}
相关问题