最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

iOS 高效的分頁加載實(shí)現(xiàn)示例

 更新時(shí)間:2017年10月17日 11:12:23   作者:藍(lán)光95  
本篇文章主要介紹了iOS 高效的分頁加載實(shí)現(xiàn)示例,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧

今天在review代碼的時(shí)候發(fā)現(xiàn)之前的tableview 和 collectview 的分頁加載邏輯還有優(yōu)化的余地,于是進(jìn)行了優(yōu)化。

一、tableview的分頁加載的代碼對(duì)比

沒有優(yōu)化之前的代碼如下:

    [strongSelf.tableView.mj_footer endRefreshing];
    [strongSelf.articleArr addObjectsFromArray:feedList];
    [strongSelf.tableView reloadData];

優(yōu)化之后的代碼如下:

    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];

二、collectonview的分頁加載的代碼對(duì)比

沒有優(yōu)化之前的代碼如下:

     [strongSelf.feedList addObjectsFromArray:feedList];
    if (feedList.count < kPageSize) {
      
      [strongSelf.collectionView.mj_footer endRefreshingWithNoMoreData];
    }else{
      
      [strongSelf.collectionView.mj_footer resetNoMoreData];
    }
    [strongSelf.collectionView reloadData];

優(yōu)化之后的代碼如下:

    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];

總結(jié):相比較之下,優(yōu)化之后看似代碼量增加了少許,但是從理論上分頁加載的性能更好了。之前分頁加載使用的全局刷新,優(yōu)化之后改用了局部刷新。從而性能得到提升。

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

平武县| 土默特右旗| 舟曲县| 西宁市| 镇坪县| 崇阳县| 阳谷县| 定远县| 诸暨市| 邯郸县| 临漳县| 罗江县| 射阳县| 武宣县| 汝州市| 逊克县| 西乡县| 年辖:市辖区| 明光市| 论坛| 黎平县| 清新县| 唐海县| 武汉市| 塔城市| 枝江市| 高青县| 治多县| 周宁县| 长子县| 扶余县| 伊川县| 江陵县| 双辽市| 舒城县| 开封市| 阜阳市| 美姑县| 蓝山县| 红安县| 西峡县|