gpt4 book ai didi

ios - 组合 moveSection :toSection, insertSections :, 和 deleteSections: 在 UITableView 更新 block 中

转载 作者:行者123 更新时间:2023-11-28 18:24:29 25 4
gpt4 key购买 nike

UITableView documentation表示可以在 beginUpdates 中合并对 moveSection:toSection:insertSections:withRowAnimation:deleteSections:withRowAnimation: 的调用-endUpdates block 。一个名为 Batch Insertion, Deletion, and Reloading of Rows and Sections 的部分在 Table View Programming Guide 中还解释说,当在更新 block 内混合插入和删除时,无论方法调用的顺序如何, TableView 都会在插入之前执行删除操作。

我的问题是,当对 moveSection:toSection: 的调用与对 insertSections:deleteSections: 的调用结合时,顺序是什么表格 View 做了什么 Action ?或者,fromSectiontoSection 是指删除之前、删除和插入之间还是插入之后的部分索引?

最佳答案

在尝试了一些代码之后,看来考虑 beginUpdates-endUpdates block 中的一批更改的最佳方式是根据部分的顺序在应用任何更新之前以及应用所有更新之后的部分顺序。如果 U 表示更新 block 之前的顺序,V 表示更新 block 之后的顺序,则 deleteSections: 调用中使用的节索引和moveSection:toSection: 中的源索引是 U 中的索引和 insertSections: 中使用的节索引以及 moveSection:toSection: 调用是 V 中的索引。

因此,例如,要对变化进行动画处理:

  0   C   ->   A   0  1   F        H   1  2   H        C   2  3   K        K   3

you could use:

[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)

如果所做的其他更改暗示了某些 Action 集,则无需明确进行。例如将 A 部分旋转到表格底部:

  0   A   ->   B  0  1   B        C  1  2   C        D  2  3   D        A  3

the following are logically equivalent:

[tableView moveSection:0 toSection:3];

[tableView moveSection:1 toSection:0];
[tableView moveSection:2 toSection:1];
[tableView moveSection:3 toSection:2];

但是它们的动画略有不同。在第一种情况下,A 部分动画向下移动到其他部分上方,而在第二种情况下,三个向上移动的部分动画显示在 A 部分上方。

最后,当为一组变化设置动画时,其中一些部分向下移动而另一些部分向上移动,不移动的部分在底部,向下移动的部分在它们上方,而向上移动的部分位于顶部。

关于ios - 组合 moveSection :toSection, insertSections :, 和 deleteSections: 在 UITableView 更新 block 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13096152/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com