首页 > 解决方案 > 重新排列表格视图单元格时出现问题

问题描述

我正在制作像 Image Gallery 这样的应用程序。当然,它有 2 个部分。我的意思是 activeImageGalleries 和 recentDeletedImageGalleries

我的表格视图单元格可以重新排列,但我希望它只是重新排列它的部分,而不是其他部分..但它不起作用

这是我的代码:

@IBAction func onEditing(_ sender: Any) {
    tableView.isEditing = !tableView.isEditing
}

override func tableView(_ tableView: UITableView, moveRowAt fromIndexPath: IndexPath, to: IndexPath) {

    if fromIndexPath.section != to.section {
        return
    }

    if fromIndexPath.section == 0 {
        let sourceImageGallery = activeImageGalleries.remove(at: fromIndexPath.row)
        activeImageGalleries.insert(sourceImageGallery, at: to.row)
    }else {
        let sourceImageGallery = recentlyDeletedImageGalleries.remove(at: fromIndexPath.row)
        recentlyDeletedImageGalleries.insert(sourceImageGallery, at: to.row)
    }

}

有人知道如何解决吗?

标签: iosswiftuitableview

解决方案


推荐阅读