UITableView 中动画插入/删除的 2 个 NSArray 的差异
在我的应用程序中的某个时刻,我有一个 NSArray,其内容发生了变化。这些内容显示在 UITableView 中。我正在尝试找到一种方法来查找 NSArray 之前和之后的内容之间的差异,以便我可以将正确的索引路径传递给 insertRowsAtIndexPaths:withRowAnimation: 和 deleteRowsAtIndexPaths:withRowAnimation: 以便使更改具有良好的动画效果。有什么想法吗?
谢谢
At some point in my Application, I have an NSArray whose contents change. Those contents are shown in a UITableView. I'm trying to find a way to find the diff between the contents of before and after of the NSArray so i can pass the correct indexPaths to insertRowsAtIndexPaths:withRowAnimation: and deleteRowsAtIndexPaths:withRowAnimation: in order to have the changes nicely animated. Any ideas?
thx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是我尝试过的,它似乎有效,如果有人有更好的东西,我很乐意看到它。
Here's is wat i tried and it seems to work, if anyone has anything better, i'd love to see it.
这个2010年的问题是我在谷歌搜索时发现的。从 iOS 5.0 开始,我们现在还有您真正想要处理的
-[UITableView moveRowAtIndexPath:toIndexPath]
。这是一个比较两个数组并为删除、插入和移动操作生成合适的索引路径的函数。有关如何使用它的示例。假设您正在显示一个人员表格,并将其保存在数组
self.people
中。显示人员的部分索引为 0。This question from 2010 is what I found when I was googling. Since iOS 5.0, we now also have
-[UITableView moveRowAtIndexPath:toIndexPath]
which you really want to handle as well. Here is a function that compares two arrays and generates suitable indexpaths for the delete, insert and move operations.An example on how to use it. Assume you're displaying a table of people, which you keep in the array
self.people
. The section index where the people are displayed is 0.