我有一个表视图,在一个部分中有两行,即
---
Row A
Row B
Run Code Online (Sandbox Code Playgroud)
如果我想将第1行设置为新部分的动画,即最终结果为:
---
Row B
---
Row A
Run Code Online (Sandbox Code Playgroud)
该如何实现?我已经尝试过的是:
[self.tableView beginUpdates];
[self.tableView deleteRowsAtIndexPaths:@[[NSIndexPath indexPathForRow: 0 inSection: 0]] withRowAnimation:UITableViewRowAnimationNone];
[self.tableView insertSections:[NSIndexSet indexSetWithIndex: 1] withRowAnimation:UITableViewRowAnimationNone];
[self.tableView endUpdates];
Run Code Online (Sandbox Code Playgroud)
但是,至少在iOS 8中,该行设置为动画,但是新部分是未渲染的(即白色,没有底行边框),直到某些东西触发重绘并返回后.
[self.tableView beginUpdates];
[self.tableView moveRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] toIndexPath:[NSIndexPath indexPathForRow:0 inSection:1]];
[self.tableView endUpdates];
Run Code Online (Sandbox Code Playgroud)
这提出了一个例外:
Invalid update: invalid number of sections. The number of sections contained in the table view after the update (2) must be equal to the number of sections contained in the table view before the update (1), plus or minus the number of sections inserted or deleted (0 inserted, 0 deleted).
Run Code Online (Sandbox Code Playgroud)
和:
[self.tableView beginUpdates];
[self.tableView insertSections:[NSIndexSet indexSetWithIndex: 1] withRowAnimation:UITableViewRowAnimationNone];
[self.tableView moveRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] toIndexPath:[NSIndexPath indexPathForRow:0 inSection:1]];
[self.tableView endUpdates];
Run Code Online (Sandbox Code Playgroud)
这引发了异常:
cannot move a row into a newly inserted section (1)
Run Code Online (Sandbox Code Playgroud)
我应该根本没有动画并重新加载整个桌子吗?
| 归档时间: |
|
| 查看次数: |
2000 次 |
| 最近记录: |