【问题标题】:Get IndexPath from a UITableViewCell's subview [duplicate]从 UITableViewCell 的子视图中获取 IndexPath [重复]
【发布时间】:2012-10-24 10:30:22
【问题描述】:

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

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

【问题讨论】:

  • @flexaddicted 谢谢,这正是我所需要的。

标签: objective-c ios cocoa-touch uitableview


【解决方案1】:
- (IBAction)recognizerAction:(id)sender {
    UITapGestureRecognizer *recognizer = sender;

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

【讨论】:

  • 我认为recognizer.view 是我的单元格的子视图,我应该从[查看超级视图] 获得MyCustomCell,无论如何,非常感谢。
猜你喜欢
  • 2012-03-23
  • 1970-01-01
  • 2014-11-10
  • 1970-01-01
  • 2013-03-20
  • 1970-01-01
  • 2023-03-19
  • 2013-04-20
  • 2014-09-25
相关资源
最近更新 更多