I am developing an application that uses SQLite. I want to show a list of users (UITableView) using a paginating mechanism. Could any one please tell me how to load more dat
Just wanna share this approach:
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
NSLog(@"%@", [[YourTableView indexPathsForVisibleRows] lastObject]);
[self estimatedTotalData];
}
- (void)estimatedTotalData
{
long currentRow = ((NSIndexPath *)[[YourTableView indexPathsForVisibleRows] lastObject]).row;
long estimateDataCount = 25;
while (currentRow > estimateDataCount)
{
estimateDataCount+=25;
}
dataLimit = estimateDataCount;
if (dataLimit == currentRow+1)
{
dataLimit+=25;
}
NSLog(@"dataLimit :%ld", dataLimit);
[self requestForData];
// this answers the question..
//
if(YourDataSource.count-1 == currentRow)
{
NSLog(@"LAST ROW"); //loadMore data
}
}
NSLog(...); output would be something like:
{length = 2, path = 0 - 92}
dataLimit :100
{length = 2, path = 0 - 83}
dataLimit :100
{length = 2, path = 0 - 79}
dataLimit :100
{length = 2, path = 0 - 71}
dataLimit :75
{length = 2, path = 0 - 59}
dataLimit :75
{length = 2, path = 0 - 56}
dataLimit :75
{length = 2, path = 0 - 39}
dataLimit :50
{length = 2, path = 0 - 36}
dataLimit :50
{length = 2, path = 0 - 1}
dataLimit :25
{length = 2, path = 0 - 1}
dataLimit :25
This is good for displaying data stored locally. Initially I declare the dataLimit to 25, that means uitableview will have 0-24 (initially).
If the user scrolled to the bottom and the last cell is visible dataLimit will be added with 25...
Note: This is more like a UITableView data paging, :)