Created
January 23, 2019 08:33
-
-
Save shishirthedev/30679846b892284e553830b043b9f7c5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
API SIDE: | |
1. Server needs to accept two paramters fromIndex and itemsLimit in the API url as query params. | |
2. Server response will provide an extra key totalItems to identify all items received or not. | |
And and array of items from fromIndex to itemsLimit. | |
APP SIDE: | |
1. First loadItem() will be called with fromIndex = 0 and batchSize = 20 (for example in viewDidLoad() | |
or viewWillAppear). removeAll items from privateList array before calling loadItem() for the first time | |
2. Server returns an array of first 20 items and totalItems total number of items in the server. | |
3. Append the 20 items in privateList array and reload tableView | |
4. In tableView:cellForRowAtIndexPath method check if the cell is the last cell. And check if totalItems (form server) is greater than privateList.count. That means there are more items in the server to load | |
5. if indexPath.row == privateList.count - 1 { // last cell | |
if totalItems > privateList.count { // more items to fetch | |
loadItem() // increment `fromIndex` by 20 before server call | |
} | |
} | |
6. Refresh after appending new items in the array when server response received. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment