tableView相关问题问题

一、tableView刷新数据后的偏移量问题

在初始化tableView时对预算高度设置如下即可解决:

    self.tableView.estimatedRowHeight = 0;
    self.tableView.estimatedSectionHeaderHeight = 0;
    self.tableView.estimatedSectionFooterHeight = 0;

二、获取tableView的当前区的索引以及设置滑动偏移量

获取滑动到当前区的索引

    //拿到当前滑动到哪个区
    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;

设置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];
    }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容