【问题标题】:IndexPath of a cell when Pinches?捏时单元格的IndexPath?
【发布时间】:2012-01-10 11:00:31
【问题描述】:

我发现 tableview 何时被 UIPinchGestureRecognizer 在cellForRowAtIndexPath 声明。现在想要找到被捏住的特定单元格的 indexPath。所以我写了这样的......

- (void)pinchDetected:(UIPinchGestureRecognizer*)gestureRecognizer {
    CGPoint p = [gestureRecognizer locationInView:tblAccountsList];
    NSIndexPath *indexPath = [tblAccountsList indexPathForRowAtPoint:p];
    NSLog(@"indexPath.row = %@", indexPath.row);
    UITableViewCell *pinchedCell  = [tblAccountsList cellForRowAtIndexPath:indexPath];
    NSLog(@"pinchedCell = %@", pinchedCell);
}

问题出在 indexPath.row 和单元格中,这两种情况的值都是 null。

所以,请有人帮我找到被夹住的 indexPath 或行。

【问题讨论】:

  • CGPoint p 获得了什么价值?

标签: iphone uitableview row pinch nsindexpath


【解决方案1】:

在行方法的单元格中,设置 cell.tag = indexpath.row 和

in - (void)pinchDetected:(UIPinchGestureRecognizer*)gestureRecognizer 再次从 cell.tag 中使用 UITableViewCell* cell = (UITableViewCell*)recognizer.view 可以得到行索引。

【讨论】:

  • 不,我没有使用自定义单元格。 cell.tag 再次显示为空
  • UITableViewCell *cell = [tblAccountsList dequeueReusableCellWithIdentifier:CellIdentifier]; cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; cell.tag = indexPath.row; UIPinchGestureRecognizer *pinchRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchDetected:)]; [tblAccountsList addGestureRecognizer:pinchRecognizer]; [pinchRecognizer 发布];
  • 如果使用 [cell addGestureRecognizer:pinchRecognizer];或 [cell.contentView addGestureRecognizer:pinchRecognizer];像这样选择器方法根本没有被调用......
  • 你澄清一件事,如果从第 2 行和第 5 行进行捏合..你想要这两行..还是你想要任何一行..
  • 我想要一个被挤压的特定单元格,即一行。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-05-24
  • 2018-06-24
相关资源
最近更新 更多