Reloaddata in Tableview loading wrong image Swift 2.0

Asked

Viewed 72 times

0

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

When I do the deletion I give a Reload in the table loading the data of a remote json, it proceeds with the deletion normally but the cell that passes it gets in the position of the one that was deleted already appears as if it was open without me having clicked on it to open.

And before giving the Reload I am using the following command

self.tableList.removeAllObjects() self.TableAgendment.reloadData()

There is a way to solve this?

1 answer

0


Are you using cell recycling? Both the UITableView as to the UICollectionView Sometimes, when they recycle a memory cell, they don’t update some of the right components. .

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

When you delete a cell, the UITableView no deinit on it. Instead, it stores the cell in the cache. When you ask for a new cell for UITableView through the method dequeueReusableCellWithIdentifier, before initializing a new one, it looks for cells in the cache and gives you a recycled cell, if any. The recycled cell will not necessarily be with values reset to those of a newly created cell.

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

  • Hello Lucas thank you, that’s right cell recycling. Also I was forgetting to reset the list that stored the status of the cells that form opened.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.