I have a UITableView comprised of custom UITableViewCells with some text and a button in them. The cell's allowSelection property is set to NO so that I can tap the button without selecting the cell.
I开发者_开发技巧 am trying to find a way to know which cell in the table was tapped when the button for that cell is pressed. Is there any way to do this???
Many thanks, Brett
Use this if your UIButton
is a direct subview of the UITableViewCell
([cell addSubview:button];
or cell.accessoryView = button;
)
- (IBAction)buttonTapped:(id)sender {
UIButton *button = (UIButton *)sender;
UITableViewCell *cell = (UITableViewCell *)button.superview;
}
Or if your UIButton
is a subview of the UITableViewCell
's contentView
([cell.contentView addSubview:button];
):
- (IBAction)buttonTapped:(id)sender {
UIButton *button = (UIButton *)sender;
UITableViewCell *cell = (UITableViewCell *)button.superview.superview;
}
精彩评论