2017-03-17 10 views
0

スクロール中にテーブルのデータをリロードする方法はありますか?APIを使用してスクロールしながらテーブルビューにデータをリロードする

私は "http:....... & start = 0 & limit = 50"のURLを持っています。 50.

でスタートし、制限値をインクリメントして、テーブル内のデータを再ロードする方法

誰もがこのための解決策を見つけることができますか?あなたは、負荷にそうするthis.Inのためのテーブルビューでより多くの機能を実装する必要があり

+0

に制限を設定することができます..howすべての時間で値が50でインクリメントです! – kb920

+0

ページネーションを追加するには?私はこの方法を使用していません。 – Justin

+0

このブログをチェックするhttp://uiroshan.github.io/2015/02/01/ios-uitableview-load-data-while-scrolling/ – kb920

答えて

0
  1. 表は、あなたが呼び出すことができる最後のセルに達すると、それがスクロールしている間、あなたは、テーブルビューのインデックスを追跡する必要がありますapiのページ番号を増やし、新しいレコードを配列に追加すると、apiから肯定的な応答が得られます。

  2. はより理解するために以下のコードを参照してください。

  3. viewDidLoadメソッド内の変数初期化

  4. arrTableData = [[NSMutableArray alloc]init]; 
    currentPage=-1; 
    hasNextPage = YES; 
    
  5. のtableView numberOfRowsInSection方法でcellForRowAtIndexPath法において

    -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
    { 
        int count = (int)arrTableData.count; 
        if (hasNextPage) 
        { 
        count++; 
        } 
        return count; 
    } 
    
  6. -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
    { 
        UITableViewCell *cell = nil; 
        if (indexPath.row<arrTableData.count) 
        { 
        //Load TableviewCell you intend to show 
        } 
        else 
        { 
         //Show loading cell 
         cell = [self loadingCell:indexPath]; 
         if (!isLoadingNextPage) 
         { 
         [self fetchData]; 
         } 
        } 
        return cell; 
    } 
    
  7. ロードセルコード

    -(UITableViewCell *) loadingCell :(NSIndexPath *)indexPath 
    { 
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleDefault reuseIdentifier:nil]; 
        cell.backgroundColor = [UIColor clearColor]; 
    UIActivityIndicatorView *activityIndicatorView =[[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite]; 
    activityIndicatorView.color = [UIColor blackColor]; 
    activityIndicatorView.center = CGPointMake(self.tblView.center.x, cell.center.y); 
    [cell.contentView addSubview:activityIndicatorView]; 
    [activityIndicatorView startAnimating]; 
    
    cell.userInteractionEnabled = NO; 
    return cell; 
    } 
    
  8. APIコールの実装

    -(void)fetchData 
    { 
        isLoadingNextPage = YES; 
        if (currentPage==-1) 
         currentPage=0; 
        //API Call 
        { 
    DLog(@"API Call Response = %@",response); 
    isLoadingNextPage = NO; 
    if (response == nil) 
    { 
        hasNextPage=NO; 
        return; 
    } 
    
    if (success) 
    { 
        if (hasNextPage) 
        { 
         currentPage++; 
        } 
        [arrTableData addObjectsFromArray:response]; 
    } 
    else 
    { 
        hasNextPage=NO; 
    } 
    //Reload tableview 
    }]; 
    } 
    

このための代替ソリューションを それの統合無限スクロールにSVPullToRefreshライブラリを使用しています。 https://github.com/samvermette/SVPullToRefresh

0
- (void)scrollViewDidScroll:(UIScrollView *)scrollView 
{ 
    if(self.comptabl.contentOffset.y >= (self.comptabl.contentSize.height - self.comptabl.bounds.size.height)) 
    { 
     if(isPageRefreshing==NO){ 
      isPageRefreshing=YES; 
      [appDelegate showIndicator:nil view1:self.view]; 
      start=start+50; 

      [self makeRequest:start]; 
      [self.comptabl reloadData]; 
      NSLog(@"called %d",start); 
     } 



    } 
} 

私はこの方法を使用していますが、私は値私はあなたがページネーションを統合したい願ってい

関連する問題