スクロール中にテーブルのデータをリロードする方法はありますか?APIを使用してスクロールしながらテーブルビューにデータをリロードする
私は "http:....... & start = 0 & limit = 50"のURLを持っています。 50.
でスタートし、制限値をインクリメントして、テーブル内のデータを再ロードする方法
誰もがこのための解決策を見つけることができますか?あなたは、負荷にそうするthis.Inのためのテーブルビューでより多くの機能を実装する必要があり
スクロール中にテーブルのデータをリロードする方法はありますか?APIを使用してスクロールしながらテーブルビューにデータをリロードする
私は "http:....... & start = 0 & limit = 50"のURLを持っています。 50.
でスタートし、制限値をインクリメントして、テーブル内のデータを再ロードする方法
誰もがこのための解決策を見つけることができますか?あなたは、負荷にそうするthis.Inのためのテーブルビューでより多くの機能を実装する必要があり
表は、あなたが呼び出すことができる最後のセルに達すると、それがスクロールしている間、あなたは、テーブルビューのインデックスを追跡する必要がありますapiのページ番号を増やし、新しいレコードを配列に追加すると、apiから肯定的な応答が得られます。
はより理解するために以下のコードを参照してください。
viewDidLoadメソッド内の変数初期化
arrTableData = [[NSMutableArray alloc]init];
currentPage=-1;
hasNextPage = YES;
のtableView numberOfRowsInSection方法でcellForRowAtIndexPath法において
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
int count = (int)arrTableData.count;
if (hasNextPage)
{
count++;
}
return count;
}
-(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;
}
ロードセルコード
-(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;
}
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
- (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);
}
}
}
私はこの方法を使用していますが、私は値私はあなたがページネーションを統合したい願ってい
に制限を設定することができます..howすべての時間で値が50でインクリメントです! – kb920
ページネーションを追加するには?私はこの方法を使用していません。 – Justin
このブログをチェックするhttp://uiroshan.github.io/2015/02/01/ios-uitableview-load-data-while-scrolling/ – kb920