ios - UITableView rows are repeating swift when reodered -


i having tableview , data populated in tableview. have edit option , clicking on user can edit position of row dragging or down.

for reordering purpose using delegate functions of tableview.

for example tableview data

a

b

c

d

now problem when click on edit button , drag top cell bottom , place last cell, , scroll tableview , down(still in editing mode) cell @ bottom (up tableview seen currently) repeated.

now after reordering bottom , scrolling , down

b

c

d

d

after searching found preapreforreuse, not working.

i using custom cell class render table cell.

class customcell: uitableviewcell {     init(frame: cgrect) {     super.init(style: uitableviewcellstyle.default, reuseidentifier: "cell")     #add 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) } } 

edit:

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) } 

it seems common problem not working me

hope understand problem.

thanks in advance.

did change model reflect change? if model has d in index 3, display there.

when move d need update model too, not table.


Comments