一、tableView刷新數(shù)據(jù)后的偏移量問題
在初始化tableView時對預(yù)算高度設(shè)置如下即可解決:
self.tableView.estimatedRowHeight = 0;
self.tableView.estimatedSectionHeaderHeight = 0;
self.tableView.estimatedSectionFooterHeight = 0;
二和蚪、獲取tableView的當(dāng)前區(qū)的索引以及設(shè)置滑動偏移量
獲取滑動到當(dāng)前區(qū)的索引
//拿到當(dāng)前滑動到哪個區(qū)
NSArray *arrVisible = self.tableView.indexPathsForVisibleRows;
NSArray *indexPaths = [arrVisible sortedArrayUsingComparator:^NSComparisonResult(id _Nonnull obj1, id _Nonnull obj2) {
NSIndexPath *path1 = (NSIndexPath *)obj1;
NSIndexPath *path2 = (NSIndexPath *)obj2;
return [path1 compare:path2];
}];
NSIndexPath *indexPath = (NSIndexPath *)[indexPaths lastObject];
NSInteger section = indexPath.section;
設(shè)置tableView的滑動偏移量
//點擊切換tableView的偏移量----進行展示
NSInteger index = [self.navButtonArray indexOfObject:button];
if (index == 0) {
[self.tableView setContentOffset:CGPointMake(0, 0) animated:YES];
}else{
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:index];
[self.tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
}