A, tableview paging code loaded Comparative
No previous optimization code is as follows
[strongSelf.tableView.mj_footer endRefreshing];
[strongSelf.articleArr addObjectsFromArray:feedList];
[strongSelf.tableView reloadData];
After the code optimization
NSMutableArray *indexPaths = [NSMutableArray array]; [feedList enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { NSIndexPath *indexPath = [NSIndexPath indexPathForRow:(strongSelf.articleArr.count + idx) inSection:0]; [indexPaths addObject:indexPath]; }]; [strongSelf.tableView.mj_footer endRefreshing]; [strongSelf.articleArr addObjectsFromArray:feedList]; [strongSelf.tableView beginUpdates]; [strongSelf.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationNone]; [strongSelf.tableView endUpdates];
Two, collectonview paging code loaded Comparative
No previous optimization code is as follows:
[strongSelf.feedList addObjectsFromArray:feedList]; if (feedList.count < kPageSize) { [strongSelf.collectionView.mj_footer endRefreshingWithNoMoreData]; }else{ [strongSelf.collectionView.mj_footer resetNoMoreData]; } [strongSelf.collectionView reloadData];
After the code optimization
NSMutableArray *indexPaths = [NSMutableArray array]; [feedList enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) { [indexPaths addObject:[NSIndexPath indexPathForItem:(strongSelf.feedList.count + idx) inSection:0]]; }]; [strongSelf.feedList addObjectsFromArray:feedList]; if (feedList.count < kPageSize) { [strongSelf.collectionView.mj_footer endRefreshingWithNoMoreData]; }else{ [strongSelf.collectionView.mj_footer resetNoMoreData]; } [strongSelf.collectionView insertItemsAtIndexPaths:indexPaths];
Summary: In comparison, after the amount of code optimization seemingly increased a little, but in theory page load performance better. Before paging loaded using the global refresh, refresh after switching to local optimization. So performance has been improved.