Berndhura / LuftKraftSport_iOS

1 stars 0 forks source link

show more than 30 articles #29

Open Berndhura opened 6 years ago

Berndhura commented 6 years ago

Paging: bis jetzt ist bei 30 schluss... zeige alle!!

Berndhura commented 6 years ago

https://stackoverflow.com/questions/35367496/swift-tableview-pagination

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

Server returns an array of first 20 items and totalItems total number of items in the server.

Append the 20 items in privateList array and reload tableView

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

if indexPath.row == privateList.count - 1 { // last cell if totalItems > privateList.count { // more items to fetch loadItem() // increment fromIndex by 20 before server call } }