Ios 重新排序/移动UITableViewCell,但向后移动
我想实现一种方法,以便能够对tableview的行进行重新排序。 在每个部分中,我只有一行。启用tableview的编辑状态时,移动指示器显示为expacted。但当我将其中一个单元格拖到另一个位置时,单元格会立即(大约1秒后)弹回到原始位置。这对我来说很奇怪,因为我已经实现了这样的重新排序功能。这两个项目之间的区别在于,新项目实现了一系列手势识别器(例如,UILongPressGestureRecognitor,UIPangestureRecognitor,UIPinchGestureRecognitor,…)。我已经考虑过一种可能性,即其中一个手势识别器正在阻止tableviewcell的拖动操作,但它不是 您可以看到下面的代码:Ios 重新排序/移动UITableViewCell,但向后移动,ios,xcode,uitableview,Ios,Xcode,Uitableview,我想实现一种方法,以便能够对tableview的行进行重新排序。 在每个部分中,我只有一行。启用tableview的编辑状态时,移动指示器显示为expacted。但当我将其中一个单元格拖到另一个位置时,单元格会立即(大约1秒后)弹回到原始位置。这对我来说很奇怪,因为我已经实现了这样的重新排序功能。这两个项目之间的区别在于,新项目实现了一系列手势识别器(例如,UILongPressGestureRecognitor,UIPangestureRecognitor,UIPinchGestureReco
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
- (NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath {
//return [NSIndexPath indexPathForRow:0 inSection:3];
return nil;
}
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath {
NSLog(@"%@", destinationIndexPath);
}
有人能帮我吗
更新:
我发现移动的tableviewcell正在移动到原始目标索引路径。这是否表示在表视图上重新加载了数据
第二次更新:
因为Andrei Shender解释了为什么我在tableView:TargetIndexPathFormovfromRowAtIndexPath:TopProposedIndexPath:method中返回nil,您可以在下面找到我的更新代码
- (NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath {
return proposedDestinationIndexPath;
//for testing purpose only
//return nil;
}
顺便说一句,当我更改代码时,我发现这个方法从未被调用。关于,应该调用它。请确保在方法中更新您的数据源:
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
多亏了这一点,我明白了问题所在。将UIPangestureRecognitor和UITableView与重新排序/移动功能相结合是一件棘手的事情
编辑tableview时,我会删除(viewcontroller视图的)手势识别器,再次禁用编辑时,我会再次添加手势识别器。为什么在此方法中返回零:
tableview:targetIndexPathForMoveFromRowAtIndexPath:toProposedIndexPath:
Hi,很好!但这只是为了测试。在当前更新中,我返回建议的目标索引路径。我将更新我的代码,在tableView:moveRowAtIndexPath:toIndexPath:
中实际更改数据源的代码在哪里?我目前正在编写这部分程序,完成后将发布我的解决方案。