how to implement loading more for table view when

2020-05-29 04:24发布

问题:

I want to load more data when view scroll to bottom,i.e. pull up to refresh, but I don't know how to display words like "Loading More..." as showing below and stop the tableview at that cell, because if use

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:10 inSection:0];
[self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionBottom animated:YES];

there's an error:

*** Terminating app due to uncaught exception 'NSRangeException', reason: '-[TNTableView _contentOffsetForScrollingToRowAtIndexPath:atScrollPosition:]: row (10) beyond bounds (0) for section (0).'

and if there's no data for tableView, loading more is still at the bottom cell, e.g. a table can show 9 rows, if there's no data for tableview, the "Loading More" cell is at the 10th row.

回答1:

I found a great example in AppCoda website, try to use it in your app.

http://www.appcoda.com/pull-to-refresh-uitableview-empty/

I've used in my app and it really worked... and it is probably what you are looking for.