1

I would like to implement what Gmail does in its app. That is, it fetches the emails in the background on a pull-to-refresh and when the data is available, it will update the UITableView. But if the user is interacting with the UITableView just before updating the UITableView, the app waits until the time the user releases his touch and then updates it. How can I achieve this on iOS and Android?

Abhinav Nair
  • 958
  • 1
  • 8
  • 29
  • I think you have to do research on pull to refresh. – Jagat Dave Mar 19 '16 at 06:49
  • I know about UIRefreshControl. But the case I am talking about is, let's say, the user is scrolling the uitableview, and while he/she is doing so, the async task has completed its task and is now ready to update the uitableview on the main thread. But since the user is scrolling, the app waits till the user completes scrolling and then updates. – Abhinav Nair Mar 20 '16 at 07:40

1 Answers1

0

There are multiple tutorials on the internet for achieving this. Basically you have to use a UIRefreshControl. Check this answer or this tutorial.

Community
  • 1
  • 1
Jelly
  • 4,522
  • 6
  • 26
  • 42
  • I know about UIRefreshControl. But the case I am talking about is, let's say, the user is scrolling the uitableview, and while he/she is doing so, the async task has completed its task and is now ready to update the uitableview on the main thread. But since the user is scrolling, the app waits till the user completes scrolling and then updates. – Abhinav Nair Mar 20 '16 at 07:35
  • I don't understand, so you want your tableview to update while scrolling or only when scrolling stops? – Jelly Mar 20 '16 at 07:57
  • I want it to wait till scrolling or tapping stops and then update. – Abhinav Nair Mar 20 '16 at 09:24
  • You can implement `optional func scrollViewDidEndScrollingAnimation(_ scrollView: UIScrollView)` method from `UITableViewDelegate` and check in it if new data was fetched and if so, add it to the table. For the check you can use a `bool`. Set it when the background request finishes and check if it is set on the method above. – Jelly Mar 20 '16 at 09:34
  • Ok. I guess that will work. Thanks for the help. Also is there anyway to check if the user is tapping on the uitableview or a cell? Becuase I want to implement the same functionality for tapping also. i.e. only update after tapping is over. – Abhinav Nair Mar 20 '16 at 09:42
  • Well, you can always add a gesture recognizer, but you can't really know if and when the user will tap the table view. – Jelly Mar 20 '16 at 09:51