怎么在iOS中實(shí)現(xiàn)一個(gè)分頁(yè)加載功能

怎么在iOS中實(shí)現(xiàn)一個(gè)分頁(yè)加載功能?相信很多沒(méi)有經(jīng)驗(yàn)的人對(duì)此束手無(wú)策,為此本文總結(jié)了問(wèn)題出現(xiàn)的原因和解決方法,通過(guò)這篇文章希望你能解決這個(gè)問(wèn)題。

創(chuàng)新互聯(lián)建站堅(jiān)信:善待客戶(hù),將會(huì)成為終身客戶(hù)。我們能堅(jiān)持多年,是因?yàn)槲覀円恢笨芍档眯刨?lài)。我們從不忽悠初訪客戶(hù),我們用心做好本職工作,不忘初心,方得始終。10余年網(wǎng)站建設(shè)經(jīng)驗(yàn)創(chuàng)新互聯(lián)建站是成都老牌網(wǎng)站營(yíng)銷(xiāo)服務(wù)商,為您提供成都網(wǎng)站設(shè)計(jì)、成都網(wǎng)站制作、網(wǎng)站設(shè)計(jì)、H5網(wǎng)站設(shè)計(jì)、網(wǎng)站制作、品牌網(wǎng)站制作、小程序制作服務(wù),給眾多知名企業(yè)提供過(guò)好品質(zhì)的建站服務(wù)。

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

沒(méi)有優(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的分頁(yè)加載的代碼對(duì)比

沒(méi)有優(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];

看完上述內(nèi)容,你們掌握怎么在iOS中實(shí)現(xiàn)一個(gè)分頁(yè)加載功能的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!

當(dāng)前名稱(chēng):怎么在iOS中實(shí)現(xiàn)一個(gè)分頁(yè)加載功能
文章位置:http://muchs.cn/article14/ihcpge.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站導(dǎo)航網(wǎng)站設(shè)計(jì)公司、網(wǎng)站內(nèi)鏈、小程序開(kāi)發(fā)、外貿(mào)建站、網(wǎng)站改版

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話(huà):028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

網(wǎng)站托管運(yùn)營(yíng)