ios - 使用 moveRowAt 方法修复顶行

标签 ios swift uitableview

美好的一天!

我正在尝试使用 moveRowAt 方法实现行的重新排列。 我的任务是修复顶行并使其不可编辑。我设法使用 canEditRowAt 方法使其不可编辑。但是我仍然可以通过将其他行放在它的位置来改变它的位置。 我怎样才能完全修复顶部单元格以进行任何类型的重新排列?

提前致谢!

enter image description here

最佳答案

您可以覆盖 UITableViewDelegate 中的实例方法 tableView(_:targetIndexPathForMoveFromRowAt:toProposedIndexPath:) 并根据需要实现。您可以查看 api 引用 here .

示例代码如下。

    override func tableView(_ tableView: UITableView, targetIndexPathForMoveFromRowAt sourceIndexPath: IndexPath, toProposedIndexPath proposedDestinationIndexPath: IndexPath) -> IndexPath {

        if proposedDestinationIndexPath.row == 0 {
            return IndexPath(row: 1, section: proposedDestinationIndexPath.section)
        } else {
            return proposedDestinationIndexPath
        }
    }

希望对您有所帮助。干杯!

关于ios - 使用 moveRowAt 方法修复顶行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58361342/

相关文章:

ios - 将属性文本转换为HTML

swift - 无法返回在函数 Swift 中创建的数组

ios - 在 Swift 中初始化一个具有多种值类型的数组

ios - 仅使UITableViewCell的特定区域触发单元格选择

iphone - 我收到错误:使用“NSArray”类型的表达式初始化“NSMutableArray *”的指针类型不兼容?

ios - 操作无法完成。 (OSStatus 错误 -10827。)

ios - 如何在没有导航栏显示在其他 View Controller 上的情况下使用 UITableViewController 进行搜索?

ios - 需要 AutoLayout UITableView 自定义单元格解决方案

iOS 应用程序在大量带有 slider 的表格单元格上崩溃

ios - ios中使用NSTimer启动NSThread