如何使用领域之间的桌子部分之间移动单元格?

发布于 2025-01-18 05:01:42 字数 757 浏览 3 评论 0 原文

在我的项目中,我将使用两个部分使用TableView。我需要使用方法-MOVERAT在一个部分或部分之间移动单元格。然后我用领域写。

在我的代码单元中,在各节之间移动,但在一个部分中,我无法交换它们。

override func tableView(\_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
    let task = sourceIndexPath.section == 0 ? importantTask[sourceIndexPath.row] : currentTask[sourceIndexPath.row] //choose from which section the task will be taken

    let type = destinationIndexPath.section == 0 ? TaskPriority.important : TaskPriority.normal // change the type of the task (it depends in which section the task will be located)

    let realm = try! Realm()
    try! realm.write {
    task.type = type // change task type to new type
   }

    tableView.reloadData()
}

In my project I am using tableView with two sections. I need to move cells within one section or between sections using the method - moveRowAt. Then I write it in Realm.

In my code cells move between sections but in one section I can't swap them.

override func tableView(\_ tableView: UITableView, moveRowAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
    let task = sourceIndexPath.section == 0 ? importantTask[sourceIndexPath.row] : currentTask[sourceIndexPath.row] //choose from which section the task will be taken

    let type = destinationIndexPath.section == 0 ? TaskPriority.important : TaskPriority.normal // change the type of the task (it depends in which section the task will be located)

    let realm = try! Realm()
    try! realm.write {
    task.type = type // change task type to new type
   }

    tableView.reloadData()
}

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文