tableView相關(guān)問(wèn)題問(wèn)題

一、tableView刷新數(shù)據(jù)后的偏移量問(wèn)題

在初始化tableView時(shí)對(duì)預(yù)算高度設(shè)置如下即可解決:

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

二、獲取tableView的當(dāng)前區(qū)的索引以及設(shè)置滑動(dòng)偏移量

獲取滑動(dòng)到當(dāng)前區(qū)的索引

    //拿到當(dāng)前滑動(dòng)到哪個(gè)區(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的滑動(dòng)偏移量

    //點(diǎn)擊切換tableView的偏移量----進(jìn)行展示
    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];
    }
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容