Search code examples
iosobjective-cuitableviewnsthreaddispatch-async

tableView still shows two rows even though I deleted one from the data source and reloaded the table


I have an NSMutableArray _conversationsArray that basically stores IDs of all the conversations a user has in my app. Based on that value I show different number of rows in the tableView. When I delete a conversation from the data source and trigger reload of the tableView, numberOfRowsInSection method triggers and by setting a breakpoint I check the number of elements (conversations) in that array:

enter image description here

Everything seems to be fine, the result is one object which is great because I had two of them before the deletion. The problem is, as you can see on the far left of the screen, both rows are still visible in the tableView (even after the breakpoint) :/ The second row should have disappeared but it didn't. It did become unresponsive to touch events, but I need it gone.

Have you ever experienced a problem like this? Any help would be greatly appreciated.

--- Update ---

Could it be that it has to do something with the threads? because it seems that the table updates as it should when the thread changes :/ I might be wrong about it as it's hard to debug


Solution

  • It looks like you're not reloading the table view on the main thread, since -tableView:numberOfRowsInSection is called on a background thread (?). In UIKit -reloadData must be called on the main thread.