UITableView常用代理数据源方法调用顺序及执行次数

说明:先执行第一模块(3次)、然后执行第二模块(section * row 次)、最后执行第三模块(section 次)

第一模块:(1执行完之后,循环执行2-5 section次),整个模块执行3次后才执行第二模块

{
    1.有几组 1次  numberOfSectionsInTableView
        【
            2.组头高 2次  heightForHeaderInSection
            3.组尾高 2次  heightForFooterInSection
            4.有几行 1次  numberOfRowsInSection
            5.每行高 row次 heightForRowAtIndexPath
          】section次
} 3次

第二模块:整个模块循环执行section*row次之后才执行第三模块

{
    6.每行是啥 1次 cellForRowAtIndexPath
    7.每行高  1次 heightForRowAtIndexPath
    8.已展示行 1次 willDisplayCell
} section * row 次

第三模块:整个模块循环执行section次

{
    9.组头是啥    1次  viewForHeaderInSection
    10.已展示组头 1次  willDisplayHeaderView
    11.组尾是啥  1次  viewForFooterInSection
    12.已展示组尾 1次  willDisplayFooterView
} section 次

UITableView滚动到顶部和滚动到底部的处理

if (_dataArr.count > 0) {//滚动到顶部
        [self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:1] atScrollPosition:UITableViewScrollPositionTop animated:YES];
    }else{//滚动到底部
        if (self.tableView.contentSize.height > self.tableView.frame.size.height){
            CGPoint offset = CGPointMake(0, self.tableView.contentSize.height - self.tableView.frame.size.height);
            [self.tableView setContentOffset:offset animated:NO];
        }
    }
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容