ReloadData in TableView Loading Wrong Image Swift 2.0

0

I have a tableview inside my ViewController, and I do some actions in each cell like expand and delete.

When I do the deletion I give a reload to the table loading the data of a remote json, it proceeds with the deletion normally however the cell that passes to is in the position of the one that was deleted already appears as if it were open without I clicked it to open.

And before giving the reload I'm using the following command

  

self.tableList.removeAllObjects ()   self.TableAgendamento.reloadData ()

Is there a way to resolve this?

    
asked by anonymous 29.05.2016 / 16:30

1 answer

0

Are you using cell recycling? Both UITableView and UICollectionView are somewhat bugged by this. Sometimes when they recycle a cell from memory, they do not update some right component.

Another thing that may be causing this problem: where do you maintain this "open" or "closed" state? In the cell itself? If it is, it could also be for the issue of cell recycling.

When you exclude a cell, UITableView does not deinit it. Instead, it saves the cell in the cache. When you request a new cell for UITableView through the dequeueReusableCellWithIdentifier method, before initializing a new one, it looks if it has cells in the cache and gives you a recycled cell, if any. The recycled cell will not necessarily have the values reset to those of a newly created cell.

So, within the method where you compose the cell, tableView(_:cellForRowAtIndexPath:) , do not forget to completely define the state of the cell.

    
30.05.2016 / 05:55