该UITableView文件说,这是确定的呼叫结合moveSection:toSection:,insertSections:withRowAnimation:以及deleteSections:withRowAnimation:在beginUpdates- endUpdates块.一节所谓的批量插入,删除和行和部分重装表视图编程指南还解释说,混合插入和删除更新区块内时,表视图不会缺失确实在插入之前,无论什么样的顺序方法打电话.
我的问题是,当调用moveSection:toSection:与调用相结合insertSections:和deleteSections:,在什么样的顺序不表视图做动作?或者,fromSection和toSection是指删除之前,删除和插入之间,还是插入之后的部分索引?
一些代码尝试后,似乎最好的方式来思考一个批次内的变化beginUpdates- endUpdates块是在应用任何更新的前后段的顺序上段的顺序进行应用的所有更新后.如果U表示更新块之前的顺序而V表示更新块之后的顺序,那么deleteSections:调用中使用的段索引和源索引中moveSection:toSection:的索引是U中的insertSections:索引以及moveSection:toSection:调用中的目标索引中使用的节索引是V中的指数.
因此,例如,为更改设置动画:
0 C -> A 0 1 F H 1 2 H C 2 3 K K 3
你可以使用:
[tableView deleteSections:@[1] withRowAnimation:UITableViewRowAnimationAutomatic]; // delete F
[tableView insertSections:@[0] withRowAnimation:UITableViewRowAnimationAutomatic]; // insert A
[tableView moveSection:2 toSection:1]; // move H
[tableView moveSection:0 toSection:2]; // move C (implied by other changes so not necessary)
Run Code Online (Sandbox Code Playgroud)
如果所做的其他更改暗示了一组移动,则无需明确地进行这些移动.例如,将A部分旋转到表格的底部:
0 A -> B 0 1 B C 1 2 C D 2 3 D A 3
以下在逻辑上是等价的:
[tableView moveSection:0 toSection:3];
Run Code Online (Sandbox Code Playgroud)
和
[tableView moveSection:1 toSection:0];
[tableView moveSection:2 toSection:1];
[tableView moveSection:3 toSection:2];
Run Code Online (Sandbox Code Playgroud)
然而,它们的动画略有不同.在第一种情况下,A部分动画向下移动到其他部分,而在第二种情况下,向上移动的三部分在A部分上动画.
最后,似乎在动画一组涉及向下移动的部分以及其他向上移动的部分时,不移动的部分位于底部,向下移动的部分位于其上方,以及移动的部分在顶部.
| 归档时间: |
|
| 查看次数: |
1142 次 |
| 最近记录: |