gpt4 book ai didi

ios - 使用 moveRowAt 方法修复顶行

转载 作者:行者123 更新时间:2023-11-28 13:26:00 26 4
gpt4 key购买 nike

美好的一天!

我正在尝试使用 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com