【问题标题】:How can I move tableview section?如何移动 tableview 部分?
【发布时间】:2018-03-15 13:30:15
【问题描述】:

我正在快速开发应用程序。我存储了名为 Categories 的异议数据。我在这里添加了tableViewImage,这里没有问题。我想将 tableview 的部分与单元格一起移动,但它没有。我写的函数如下。请帮助我。谢谢。

func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool {
    return true
}
func tableView(_tableview:UITableView, moveRowAtIndexPath sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath)
{
let temp = categories[sourceIndexPath.section]
categories[sourceIndexPath.section] =  categories[destinationIndexPath.section];
categories[destinationIndexPath.section] = temp
}

func tableView(_ tableView: UITableView, shouldIndentWhileEditingRowAt indexPath: IndexPath) -> Bool {
    return false
}
func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCellEditingStyle {
    return .none
}

【问题讨论】:

    标签: swift uitableview drag-and-drop


    【解决方案1】:

    您可以尝试使用这种方法,指定要移动的部分的位置以及您希望它在末尾的位置:

    table.moveSection(0, toSection: 1)
    

    您也可以尝试删除 IndexSet 或适当位置中的部分,将表格的部分数量减去 1,然后重新插入部分并将部分增加 1

    let index = IndexSet(integer: 0)
    self.number_sections -= 1
    table.deleteSections(index, with: .fade)
    
    let newIndex = IndexSet(integer: 1)
    self.number_sections += 1
    table.insertSections(newIndex, with: .fade)
    

    【讨论】:

    • 嗨天使,我试过你说的。但我想做的是拖放和重新排序部分
    • :D 我明白了,您应该编辑您的问题以指定该详细信息
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-22
    • 1970-01-01
    • 1970-01-01
    • 2015-12-13
    相关资源
    最近更新 更多