iOS:将表格单元格移动到另一个部分

发布于 2024-12-23 14:23:37 字数 157 浏览 5 评论 0原文

我有一个带有一些部分和行的 UITableView。

当我调用函数时,我想将一行从一个部分移动到另一部分(所以不是我的手指,我不想使用 UITableView 的编辑模式)。

我该怎么做?

如果我重新创建数据源并重新加载表,那就可以了,但它不使用动画。

I have a UITableView with some sections and rows.

I want to move one row from one section to another section, when I call a function (so not my fingers and I do not want use edit mode of UITableView).

How can I do this?

If I recreate a datasource and reload table, it's ok, but it not use animation.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

断念 2024-12-30 14:23:37

UITableView 为您提供了执行此操作的方法:

调用 beginUpdates、更新数据源、调用 moveRowAtIndexPath 并最终在 UITableView 上调用 endUpdates

[tableView beginUpdates];

// update your datasource
// ... 

// fill in your indexpath of old and new position
[tableView moveRowAtIndexPath: ... toIndexPath: ...];
[tableView endUpdates];

编辑:moveRowAtIndexPath 仅适用于 iOS 5+
所以你宁愿使用这个:

[tableView insertRowsAtIndexPaths: ... withRowAnimation:...];
[tableView deleteRowsAtIndexPaths: ... withRowAnimation:...];

UITableView offers you methods for this:

call beginUpdates, update your datasource, call moveRowAtIndexPath and finally call endUpdates on UITableView

[tableView beginUpdates];

// update your datasource
// ... 

// fill in your indexpath of old and new position
[tableView moveRowAtIndexPath: ... toIndexPath: ...];
[tableView endUpdates];

EDIT: moveRowAtIndexPath is only for iOS 5+
so you would rather use this:

[tableView insertRowsAtIndexPaths: ... withRowAnimation:...];
[tableView deleteRowsAtIndexPaths: ... withRowAnimation:...];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文