I've been searching a lot, but I don't find a clear way to create an Scroll to top load more, or infinite scroll, just like you see on chats, e.g whatsapp. I was trying using scrollViewDidScroll method, load data again based on current page
if self.tableView.contentOffset.y == 0 {
loadData(++currentPage, itemsPerPage: pageSize)
}
But the way to handle new data and scroll position it's a little weird for me, so the main problem is adding content in an efficient way, at the top of my UITableView
//Update
In ScrollViewDidScroll method:
After contentOffset.y reaches 0 position, I'm trying to prepend new messages, since it must appear at top of UITableView, so inserting messages at index 0 is the only way I find to do this. But there is one thing, after pulling new data, and reloading UITableView, scroll position remains displaying at visible screen, last pulled message on top. This is not the expected behaviour, look this slack channel pic
when scroll reached proper offset, new data was pulled, and screen it's on the same message, but looks now the scroll position
so, I think reloading entire table view in this case is the problem, but how could you pull the data in the tableView properly to get this expected scroll behaviour?
e.g in whatsapp it's the same
