Objective-C UITableView lifecycle
UITableView的执行顺序
- 它会调用代理方法确定有几个section
[TableViewController numberOfSectionsInTableView:] - 确定每行的表头高和表尾高(如果设定了HeardView和FooterView)可以不实现这个
[TableViewController tableView:heightForHeaderInSection:]
[TableViewController tableView:heightForFooterInSection:] - 确定每行有多少的cell
[TableViewController tableView:numberOfRowsInSection:] - 然后确定每行cell的高度必须实现这个函数 即返回cell的高度,可以返回一个自动高度 如果不返回,将无法绘制出cell
[TableViewController tableView:heightForRowAtIndexPath:] - 以上信息确定完毕后及调用代理方法去获取cell 在此获得具体的cell 可以初始化cell视图在这里然后返回一个cell
[TableViewController tableView:cellForRowAtIndexPath:] - 返回cell的高度
[TableViewController tableView:heightForRowAtIndexPath:] - cell将要显示到屏幕上
[TableViewController tableView:willDisplayCell:forRowAtIndexPath:] - cell超出屏幕进行服用时及会调用两次
[TableViewController tableView:heightForRowAtIndexPath:]
然后在进行调用 5 . 6. 7 方法