UITableView does not load the new state if user scrolling

252 Views Asked by At

SOLVED: It is not about UITableViewDiffableDataSource. The problem was accessing realm from 2 different thread sequentially and not getting consistent result

One of the thread was main thread and scrolling somehow kept main thread busy and triggered race condition


Everything works if user not scrolling tableview when update is happening.

If user is scrolling or just have finger on the tableview, no animations happening on update and differences does not show up. I am not getting any error in the console

Data update code is like below:

var snapshot = tableViewDataSource.snapshot()
snapshot.deleteAllItems()
snapshot.appendSections([.conversation])
snapshot.appendItems(conversationList, toSection: .conversation)
tableViewDataSource.apply(snapshot)

Is this somehow an expected behavior?

1

There are 1 best solutions below

1
user1922718 On

In my experience, you have to be cognizant of when UI updates occur. UI updates always occur on the main thread.

When the user is actively scrolling, I believe this blocks the main thread, so your diffable data source is likely updating, but your app cannot update the UI until the user releases his/her finger from the display.