我需要你的帮助..
我有一个UIPanGesture
在我的习惯TableViewCell
。UITableView
我应该需要确定在's中已平移了哪个单元格UIViewController
。
我有两个问题:
我怎样才能被平移
TableViewCell
(也许通过 indexpath)..我应该把代码放在
UITableView
's 方法中的哪里来获取它。
非常感谢!!!
安德烈亚
我需要你的帮助..
我有一个UIPanGesture
在我的习惯TableViewCell
。UITableView
我应该需要确定在's中已平移了哪个单元格UIViewController
。
我有两个问题:
我怎样才能被平移TableViewCell
(也许通过 indexpath)..
我应该把代码放在UITableView
's 方法中的哪里来获取它。
非常感谢!!!
安德烈亚
我用这行代码解决了我的问题: SCViewController vista = (SCViewController )tableview.dataSource; vista.swipedIndexPath = _PannedIndexpath; 通过这种方式,我发送到位于 uitableviewcell 中的表格视图滑动单元格的索引路径。
如果我正确阅读了您的问题,听起来您想向每个表格视图单元格添加滑动手势,然后能够获取该单元格的索引。如果这是您正在寻找的内容,您可以随时执行以下操作。这看起来类似于这个问题:How to detect a swipe-to-delete gesture in a custom UITableviewCell? 但我确实为你包括了实现:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//Do what you need to to get your current cell
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifer:@"prototypeCellId";
//create swipe gesture and add it to cell
UISwipeGestureRecognizer* swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(cellSwiped:)];
[swipeRecognizer setDirection:UISwipeGestureRecognizerDirectionRight];
[cell addGestureRecognizer:swipeRecognizer];
return cell;
}
- (void)cellSwiped:(UIGestureRecognizer *)gestureRecognizer
{
if (gestureRecognizer.state == UIGestureRecognizerStateEnded)
{
UITableViewCell *cell = (UITableViewCell *)gestureRecognizer.view;
NSIndexPath* indexPath = [self.tableView indexPathForCell:cell];
//do what you want with the indexPath (or cell)
}
}
如果我理解正确,您想弄清楚 UIPanGesture 在 UITableView 的哪一部分结束,对吗?
我会使用 UITableView 方法 indexPathForRowAtPoint: 来获取您的 indexPath。
我没有使用手势识别器的经验,但如果我有机会获得一个工作示例,我会更新我的答案。如果您可以详细说明 UIPanGesture 正在做什么或为什么您需要 UITableViewCell ,那将有所帮助。