2

Using Swift4.1, iOS11.3.1 and Xcode 9.3,

I have a conflict going on between tableView.scrollToRow(at: and the tableView-delegate method cellForRowAt indexPath:

The procedure is as follows:

  1. network-fetch of data1
  2. call tableView.reloadData() (..filling a tableView with this data1)
  3. scroll to a defined cell (...so far so good everything works and data1 shows..) But then if I add...
  4. during all of the above - I do a background-fetch of additional data2
  5. when fetched, calling tableView.reloadData() again (filling the the additional data2 as well in the same tableView)

Now - it seems that the additional-data2 fetch is coming in right at the moment where the scroll is carried out. In this case, the scrolling interferes with the cellForRowAt of the additionally fetched data. This leads to cell-order that is completely corrupt !!

The needed solution:

How can I detect the data1-scroll's ending moment (in order to hold back the background-fetch's reloadData()) until the scrolling is done ??

Any help on this appreciated.

iKK
  • 6,394
  • 10
  • 58
  • 131
  • Your immediate question is probably answered here: [how to check when UITableView is done scrolling](https://stackoverflow.com/questions/16521681/how-to-check-when-uitableview-is-done-scrolling). – Martin R Apr 29 '18 at 17:38
  • 1
    On the other hand, this looks like an XY problem. If the cell order is “completely corrupt” then you are doing something wrong. Also loading additional data does not necessarily require that you reload the entire table view. You can *merge* in a beginUpdates/endUpdates context. – Martin R Apr 29 '18 at 17:39
  • Thank you, Martin ! I will have a look at this begin/endUpdate context in more depth... – iKK Apr 29 '18 at 18:12

0 Answers0