當我滾動到我的tableview的底部,並獲取更多的數據與下一個偏移量,我將新的對象添加到我的數據數組。然而,我的tableview重新加載並返回到第一個單元格。我試圖阻止這一點。Tableview在添加新數據時滾動到頂部。無限滾動
- (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");
}
});
}
];
}
編輯嘗試添加該
- (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");
}
});
}
];
}
還是滾動到頂部
我不認爲我很清楚。我的意思是我的tableview自動進入頂層單元格。我試圖阻止這一點。所以用戶可以繼續滾動瀏覽下一頁的新條目 – mparrish91
,那麼你想滾動底部意味着你的最後一個單元? –
是對最後一個單元格。當用戶在桌面上向下滑動並請求下一頁時。有桌面停留並顯示下一頁。 – mparrish91