When I scroll to the bottom of my tableview and fetch more data with the next offset, i add the new objects to my data array. My tableview however reloads and returns to the first cell. I'm trying to prevent this.
- (void)fetchMovies {
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
[self.networkingHelper fetchNowPlayingWithCompletionHandler:^(NSArray *objects, NSError *error) {
if (error) {
[self showErrorView:self.errorView];
} else {
[self hideErrorView:self.errorView];
}
[self.movies addObjectsFromArray:objects];
self.displayedItems = self.movies;
dispatch_async(dispatch_get_main_queue(), ^{
self.isMoreDataLoading = false;
if ([[NSThread currentThread] isMainThread]){
NSLog(@"In main thread--completion handler");
[self.refreshControl endRefreshing];
[self.loadingMoreView stopAnimating];
[MBProgressHUD hideHUDForView:self.view animated:YES];
} else {
NSLog(@"Not in main thread--completion handler");
}
});
}
];
}
Edit Tried adding this
- (void)fetchMovies {
[MBProgressHUD showHUDAddedTo:self.view animated:YES];
[self.networkingHelper fetchNowPlayingWithCompletionHandler:^(NSArray *objects, NSError *error)
{
if (error)
{
[self showErrorView:self.errorView];
}
else
{
[self hideErrorView:self.errorView];
}
[self.movies addObjectsFromArray:objects];
self.displayedItems = self.movies;
dispatch_async(dispatch_get_main_queue(), ^{
self.isMoreDataLoading = false;
if ([[NSThread currentThread] isMainThread]){
NSLog(@"In main thread--completion handler");
CGFloat oldOffset = self.moviesTableView.contentSize.height;
[self.moviesTableView reloadData];
CGFloat onewOffset = self.moviesTableView.contentSize.height;
CGPoint new = CGPointMake(0, onewOffset - oldOffset);
[self.moviesTableView setContentOffset:new];
[self.refreshControl endRefreshing];
[self.loadingMoreView stopAnimating];
[MBProgressHUD hideHUDForView:self.view animated:YES];
}
else{
NSLog(@"Not in main thread--completion handler");
}
});
}
];
}
Still scrolls to top