Guest User

Untitled

a guest
Dec 18th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. func refresh() {
  2. currentPage = currentPage + 1
  3.  
  4. if currentPage <= totalPages {
  5. fetchMessaes(page: self.currentPage, completed: {
  6.  
  7. self.messageArray.append(contentsOf: self.fetchedMessages!.messages!)
  8.  
  9. // Sort message by ID so that latest message appear at the bottom.
  10. let sortedArray = self.messageArray.sorted(by: {$0.id! < $1.id!})
  11. self.fetchedMessages = sortedArray
  12.  
  13. self.messagesTable.reloadData()
  14.  
  15. // Scroll to the last row of recently loaded messages
  16. DispatchQueue.main.async {
  17. let index = IndexPath(row: 0, section: 0)
  18. self.messagesTable.scrollToRow(at: index, at: .top, animated: false)
  19. }
  20. })
  21. }
  22. refreshControl.endRefreshing()
  23. }
Add Comment
Please, Sign In to add comment