I have some static UITableViewCell
s. One of them with 5 buttons inside. Inside didSelectRowAtIndexPath
I handle the selection event for all the cells except for the one with the buttons inside. The problem is the action for the buttons in that one cell does not work.
Any help will be appreciated.
IBAction for Buttons inside static Cell do not work with didSelectRowAtIndexPath is overrided
706 views Asked by Abdelrahman At
2
There are 2 answers
0
On
You don't have the cellForAtIndexPath
method, however you can implement the tableView:willDisplayCell:forRowAtIndexPath:
method and add target for each button like so:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
// get a reference to button
UIButton *button = (UIButton *)[cell viewWithTag:1];
[button addTarget:self action:@selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
}
Finally I figured out That the root of the problem was at a completely different area,
heightForRowAtIndexPath
was returning wrong height for that cell (actually smaller height),So, the controller interpreted the touches to be in a completely different place than the actual place I was supposedly touching