Getting the Custom UITableViewCell from its superview in iOS7

I am getting the custom UITableViewCell on button click.
It worked fine in iOS5/6 but crashed in iOS7.

- (void)handleClick:(id) sender {
  // use superview
  UITableViewCell *clickedCell = (UITableViewCell *)[[sender superview] superview];
  NSIndexPath *indexPath = [self.tableView indexPathForCell:clickedCell];
  NSLog(@"indexPath:%d, textLabel:%@", indexPath.row, clickedCell.textLabel.text);

I got this error in iOS7.

[UITableViewCellScrollView btn]: unrecognized selector sent to instance

For iOS7: Apple has changed the view hierarchy.

UITableViewCell *clickedCell = (UITableViewCell *)[[[sender superview] superview] superview];

It's better to fix this with position.

  // use position
  CGPoint btnPosition = [sender convertPoint:CGPointZero toView:self.tableView];
  NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:btnPosition];
  UITableViewCell *clickedCell = (UITableViewCell *)[self.tableView cellForRowAtIndexPath:indexPath];


iOS8 又改回來,所以比較好的方式是用 position 來取得 indexPath。