从UITableViewCell的子视图中获取IndexPath

时间:2012-11-04 10:18:00

标签: objective-c ios cocoa-touch uitableview

  

可能重复:
  Detecting which UIButton was pressed in a UITableView

这是我的情况,我将UITapGestureRecognizer添加到我的自定义UITableViewCell的子视图中,我将识别器的目标设置为我的tableviewcontroller,所以我想知道如何从我的这个单元格的indexPath中获取tableviewcontroller的动作方法。

1 个答案:

答案 0 :(得分:0)

- (IBAction)recognizerAction:(id)sender {
    UITapGestureRecognizer *recognizer = sender;

    if (recognizer.state == UIGestureRecognizerStateRecognized) {
        YourCell *cell = (YourCell *)recognizer.view;
        NSIndexPath *indexPath = [yourTableView indexPathForCell:cell];
        [self doSomethingWithIndexPath:indexPath];
    }
}