我有一个表格,当您选择一个项目时,它会更改该单元格中该对象的一些内容,然后将该单元格移动到底部,然后重新加载表格数据。
//update model
...
//move cell to bottom
[tableView beginUpdates];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationBottom];
[tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:lastIndex inSection:0]] withRowAnimation:UITableViewRowAnimationTop];
[tableView endUpdates];
//reload cells
[tableView reloadData];
目前,它可以工作,但不会等待动画完成。如何等待插入和删除动画完成后再重新加载数据?或者如果有更好的方法,也很高兴知道。
最佳答案
很简单,您可以使用 UITableView 的 moveRowAtIndexPath
来将单元格从起始点移动到结束点,而不是删除一个单元格然后立即添加一个新单元格。
[tableView moveRowAtIndexPath:[NSArray arrayWithObject:indexPath] toIndexPath:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:lastIndex inSection:0]]];
关于objective-c - 添加和删除单元格时如何知道 UITableView 何时完成动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13745541/