2017-01-09 42 views
0

如何使用call api在UITableView中進行分頁(加載更多數據,如facebook)? 代碼: -如何使用call api在uitableview中進行分頁?

-(void)scrollViewDidScroll:(UIScrollView *)scrollView 
{ 
    CGFloat height = scrollView.frame.size.height; 

    CGFloat contentYoffset = scrollView.contentOffset.y; 

    CGFloat distanceFromBottom = scrollView.contentSize.height - contentYoffset; 

    if(distanceFromBottom < height) 
    { 

     [self fetchNewsFeeds:[filteredArray count]+1 withLimit:20]; 

     NSLog(@"end of the table"); 
    } 
} 

滾動高達內容高度後不能調用API

+0

搜索:「負載越來越懶加載與表視圖」 –

+0

你實際上是什麼感覺問題@Bhavesh Rathod –

+0

https://github.com/MrAlek/AWPagedArray,它會給你全部的東西。 –

回答

0

存儲響應數據在NSArray中,然後添加到一個NSMutableArray的

NSArray *resObj = [NSArray alloc] init]; 
NSMutableArray *aMutArray = [NSMutableArray alloc] init]; 
[aMutArray addObject: resObj]; 

//檢查的最後一個索引tableview 在cellForItemAtIndexPath中寫入該代碼

if(lastIndex) 
    { 
     // show load more button 
    } 
0

取兩個部分:第一部分中的行包含您要顯示的項目,第二部分包含一行其單元格有UIActivityIndicator的行。

然後執行給定的委託方法:

func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) { 

    if indexPath.section == 1 { 

     let footercell = cell as! ProductFooterCollectionViewCell 
     footercell.loader.startAnimating() 
     fetchSearchProducts() 
    }    
} 
0

泰伯維代表當顯示單元調用此方法:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    NSInteger totalRow = [tableView numberOfRowsInSection:indexPath.section];//first get total rows in that section by current indexPath. 
    if(indexPath.row == totalRow-1) 
    { 
     // Code... 
    } 
} 

希望你解決問題。

+0

我用這個解決辦法,但我喜歡循環 –

0

你需要先找到你tableviewcell的最後一排。

下面是尋找最後一行代碼:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
     NSInteger totalNumberOfRows = [tableView numberOfRowsInSection:indexPath.section]; 

// isLoadMore flage is TRUE when there is more data available. 
     if(indexPath.row == totalNumberOfRows-1 && isLoadMore) 
     { 
      // Code... 
      // Here you need to check if there are some load more data is there from pervious web-service or not. 
    // If there is load more then call web-service and another set of data. 
     } 
    } 

您可以使用AFNetworking讓打電話給你的web服務。

希望你得到的邏輯:)

+0

代碼來看,我用這個解決方案,但運行像環 –

+0

我的代碼你需要把檢查,如果沒有更多的數據負載更多,然後設置一個flage和weillDisplayCell方法來檢查的條件。檢查我的更新情況。 – Nirmalsinh