NSIndexPath *sourceIndexPath = [_mainTableView indexPathForCell:cell];
NSIndexPath *destinationIdexPath = [NSIndexPath indexPathForRow:2 inSection:(2)];
[CATransaction begin];
[CATransaction setCompletionBlock:^{
// Your completion code here
[_mainTableView reloadData];
}];
//一定要加上这个,否则不同机型可能会有崩溃
[_mainTableView beginUpdates];
[_mainTableView moveRowAtIndexPath:sourceIndexPath toIndexPath:destinationIdexPath];
[_mainTableView endUpdates];
[CATransaction commit];
本文介绍如何使用Swift在UITableView中移动单元格,通过NSIndexPath获取源位置和目标位置,利用CATransaction进行流畅的动画处理,确保在不同设备上操作的稳定性和一致性。
2513

被折叠的 条评论
为什么被折叠?



