我有一个tableview,一些数据被填充到tableview中。现在我有了一个编辑选项,单击它,用户可以通过向上或向下拖动来编辑行的位置。
为了重新排序,我使用了tableView的委托函数。
例如,这是tableView数据
一个

C类

现在的问题是,当我单击“编辑”按钮并将最上面的单元格拖到最下面并将其作为最后一个单元格放置,然后上下滚动tableView(仍处于编辑模式)时,底部的单元格(当前可以看到tableView)将重复。
在将A重新排序到最下面,然后上下滚动之后

C类


搜索之后,我找到了preforreuse,但它不起作用。
我正在使用自定义单元格类来呈现表单元格。

class customCell: UITableViewCell {
init(frame: CGRect) {
    super.init(style: UITableViewCellStyle.Default, reuseIdentifier: "cell")
    #add the details
}

required init(coder aDecoder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
}

override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
    super.init(style: style, reuseIdentifier: reuseIdentifier)
}
}

编辑:
override func tableView(tableView: UITableView, moveRowAtIndexPath sourceIndexPath: NSIndexPath, toIndexPath destinationIndexPath: NSIndexPath) {
    var sdata = self.data[sourceIndexPath.row]
        self.data.removeAtIndex(sourceIndexPath.row)
        self.data.insert(sdata, atIndex: destinationIndexPath.row)
}

这似乎是很常见的问题,但对我不起作用
希望你能理解这个问题。
提前谢谢。

最佳答案

你是不是为了反映变化而改变了你的模型?如果您的模型在索引3中有D,那么这就是您将在那里显示的内容。
当您将A移动到D时,您也需要更新模型,而不仅仅是表。

关于ios - UITableView行在重新编排时重复快速,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31530819/

10-14 22:28
查看更多