捏时单元格的IndexPath?
Posted
技术标签:
【中文标题】捏时单元格的IndexPath?【英文标题】:IndexPath of a cell when Pinches? 【发布时间】: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
获得了什么价值?
【参考方案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 行进行捏合..你想要这两行..还是你想要任何一行.. 我想要一个被挤压的特定单元格,即一行。以上是关于捏时单元格的IndexPath?的主要内容,如果未能解决你的问题,请参考以下文章
快速获取collectionView中心单元格的indexPath?