我有一个 UITableView
,其中添加了 UISwipeGesture
,如下所示:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
CustomCell *cell = (CustomCell*)[tableView dequeueReusableCellWithIdentifier:kCellIndetifier];
UISwipeGestureRecognizer* gestureR;
gestureR = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom)];
gestureR.direction = UISwipeGestureRecognizerDirectionLeft;
[cell addGestureRecognizer:gestureR];
return cell;
}
我的选择器在滑动时有响应。
现在我想基于 SwipeGesture
操作单元格。但我无法获取 indexPath
和 UITableView
。我怎样才能让这些来操纵细胞。或者他们有其他方式这样做吗?
请帮助我。
最佳答案
你可以做如下的事情..
UISwipeGestureRecognizer* gestureR;
gestureR = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeFrom:)];
gestureR.direction = UISwipeGestureRecognizerDirectionLeft;
[cell addGestureRecognizer:gestureR];
-(void)handleSwipeFrom:(UIGestureRecognizer *)tap{
CGPoint touch = [tap locationInView:yourtableview];
NSIndexPath *indexPath = [yourtableview indexPathForRowAtPoint:touch];
CustomCell *cell = [yourtableview cellForRowAtIndexPath:indexPath];
}
让我知道它是否有效。
祝你编码愉快!!!
关于ios - 如何通过滑动手势获取 IndexPath 和 UItableView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33117950/