If your button is moved or Apple changes the view hierarchy for accessories, this method goes up the chain to look for a UITableViewCell:
- (void)tapAccessoryButton:(UIButton *)sender { UIView *parentView = sender.superview; // the loop should take care of any changes in the view heirarchy, whether from // changes we make or apple makes. while (![parentView.class isSubclassOfClass:UITableViewCell.class]) parentView = parentView.superview; if ([parentView.class isSubclassOfClass:UITableViewCell.class]) { UITableViewCell *cell = (UITableViewCell *) parentView; NSIndexPath *indexPath = [self.tableView indexPathForCell:cell]; [self tableView:self.tableView accessoryButtonTappedForRowWithIndexPath:indexPath]; } }
source share