我加入新的數據到tableView
當用戶滾動到這樣的底部....加載更多的細胞,當用戶滾動到的tableview框架的底部
- (void)scrollViewDidScroll:(UIScrollView *)aScrollView {
float height = self.itemListTableView.frame.size.height;
float contentYoffset = aScrollView.contentOffset.y;
float distanceFromBottom = aScrollView.contentSize.height - contentYoffset;
if (distanceFromBottom < height) {
NSLog(@" you reached end of the table");
isTableScrolledToBottom = YES;
}else{
isTableScrolledToBottom = NO;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"CellIdentifier";
ListViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell==nil){
cell = [[ListViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
//Assign values to labels here..
if (isTableScrolledToBottom) {
if (indexPath.row == [apiMutableArray count]-1)
{
// Call the API
NSLog(@"Call the api");
int pgn = [self.currentPageNumber intValue];
pgn = pgn+1;
self.currentPageNumber = [NSNumber numberWithInt:pgn];
NSLog(@"incremented page number : %@",self.currentPageNumber);
NSMutableDictionary *mutableDict = [self.poPostDict mutableCopy];
[mutableDict setObject:self.currentPageNumber forKey:@"pageno"];
self.poPostDict = [mutableDict mutableCopy];
[self addLoaderViewAtBottom];
[self loadPOData:self.poPostDict];
}
}
return cell;
}
現在,如果在表視圖中的數據是大足夠了,用戶將滾動到底部,並按預期從api完成數據提取。但是,當我過濾此表並讓我說只有一行數據時。 在這種情況下,即使我可以看到表格中只有一個單元格,如果我嘗試滾動表格,則會觸發api請求。 如何真正知道用戶是否已經滾動到其frame
以上,並且最終達到scrollView's
,因此只有在這種情況下我才能獲取數據。
注意: - 使用當前的技術,如果只有一行是存在的,我嘗試滾動,API調用連續命中而不停止。
解決方案已經出現在堆棧上。你有沒有嘗試過任何一個? –
我發現這些技術在堆棧本身。但是,如果我過濾表的解決方案似乎並不工作。 – icodes
您不需要過濾必須添加數據的數據。 –