Rob Sparks
Rob Sparks

Reputation: 77

Swift - Reload the last 20 rows in A UITableView

I'm working on a news page in an app and am attempting to reload the last 20 rows in a TableView controller whenever a fetch request is made to our API. Results are loaded in batches of 20, and I'd prefer not to reload the whole TableView whenever 20 more results are added to the table, as this causes flickering on fast scrolling.

I know I should use self.tableView.reloadRowsAtIndexPaths(), but I'm not sure as to how I obtain the index paths of last 20 rows in the table.

Upvotes: 0

Views: 315

Answers (1)

nachshon f
nachshon f

Reputation: 3680

Use a for loop...

if there are 30 rows, this method will reload the last 20 rows (row 10 - 30). Remember, the index paths start at row 0 not 1.

for (var i = 9; i < 29; i++) {

self.tableView.reloadRowsAtIndexPaths(i)

}

Upvotes: 2

Related Questions