I am working on a simple iPhone app that is loading data from the web service (RSS feed) inside UITableView. The first time app is loading, i am using a counter with initial value of 1 to load the first page of the feed:
- (void)viewDidLoad
{
[super viewDidLoad];
counter = 1;
[self fetchEntriesNew:counter];
}
When the user scrolls down to the bottom of tableview, i am using the following method to load more data in the tableview by fetching the next page of rss feed by incrementing the counter:
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
float endScrolling = scrollView.contentOffset.y + scrollView.frame.size.height;
if (endScrolling >= scrollView.contentSize.height)
{
NSLog(@"Scroll End Called");
counter++;
[self fetchEntries:counter];
}
}
The counter is incrementing each time user scrolls down to the bottom of tableview, hence calling the next page of the rss feed. To this point, everything is working fine.
BUT, if the user after reaching at the bottom, scrolls up multiple times, the counter also gets incremented multiple times, hence a different page of the rss feed is reached and added to the bottom of the tableview.
To be more precise, if the user has reached to the bottom and scrolled up 3 times, instead of loading the second page, it will load the fourth page (3 times scrolled plus 1 already added in the start)
How can i restrict to not add another page entries if the one before it was not loaded?
Kindly do not suggest alternative strategies for handling more rows at the bottom of tableview or any third party libraries like NMPaginator and PartialTable etc. Thanks in advance!
UPDATE:
I have closely observed the app by running it again and again. It seems like if the user scrolls to the bottom (that increments the counter) before tableview is finished loading the page data (including images) that is already requested, it will just ignore loading the one that is currently loading and start loading the next one based on the incremented counter.