I have a custom UITableViewCell that ha开发者_运维问答s 2 buttons and a label on it. The problem is that willSelectRowAtIndexPath only gets called when I click right above the bottom of a cell.
I set User Interaction Enabled to true for the UITableViewCell. This allows the buttons I have in my cell to be clickable.
If I set it to false, I willSelectRowAtIndexPath gets called when I click anywhere in the cell but the buttons no longer work.
Please help!
I am not sure if the button can let that happen automatically when enabled. However we can let the cell know that it was selected.
- (IBAction)respondToClick:(id)sender {
CustomTableViewCell *customCell = (CustomTableViewCell*)sender.superview;
// You can signal the cell to select itself (will not send the delegate message)
[customCell setSelected:YES animated:NO];
// Alternately this can be done but I don't recommend
NSIndexPath *indexPath = [myTableView indexPathForCell:customCell];
if ( myTableView.delegate && [myTableView.delegate respondsToSelector:@selector(tableView:willSelectRowAtIndexPath:)] ) {
[myTableView.delegate tableView:myTableView willSelectRowAtIndexPath:indexPath];
}
}
精彩评论