当两个section的cell数量都为5的时候,方法的调用顺序:spa
-[ViewController numberOfSectionsInTableView:]
-[ViewController tableView:titleForHeaderInSection:]
-[ViewController tableView:titleForFooterInSection:]
-[ViewController tableView:numberOfRowsInSection:], section = 1
-[ViewController tableView:titleForHeaderInSection:]
-[ViewController tableView:titleForFooterInSection:]
-[ViewController tableView:numberOfRowsInSection:], section = 0it
-[ViewController numberOfSectionsInTableView:]
-[ViewController tableView:titleForHeaderInSection:]
-[ViewController tableView:titleForFooterInSection:]
-[ViewController tableView:numberOfRowsInSection:], section = 1
-[ViewController tableView:titleForHeaderInSection:]
-[ViewController tableView:titleForFooterInSection:]
-[ViewController tableView:numberOfRowsInSection:], section = 0io
-[ViewController numberOfSectionsInTableView:]
-[ViewController tableView:titleForHeaderInSection:]
-[ViewController tableView:titleForFooterInSection:]
-[ViewController tableView:numberOfRowsInSection:], section = 1
-[ViewController tableView:titleForHeaderInSection:]
-[ViewController tableView:titleForFooterInSection:]
-[ViewController tableView:numberOfRowsInSection:], section = 0table
-[ViewController tableView:cellForRowAtIndexPath:], section = 0, row = 0
-[ViewController tableView:cellForRowAtIndexPath:], section = 0, row = 1
-[ViewController tableView:cellForRowAtIndexPath:], section = 0, row = 2
-[ViewController tableView:cellForRowAtIndexPath:], section = 0, row = 3
-[ViewController tableView:cellForRowAtIndexPath:], section = 0, row = 4
-[ViewController tableView:cellForRowAtIndexPath:], section = 1, row = 0
-[ViewController tableView:cellForRowAtIndexPath:], section = 1, row = 1
-[ViewController tableView:cellForRowAtIndexPath:], section = 1, row = 2
-[ViewController tableView:cellForRowAtIndexPath:], section = 1, row = 3
-[ViewController tableView:cellForRowAtIndexPath:], section = 1, row = 4
-[ViewController tableView:titleForHeaderInSection:]
-[ViewController tableView:titleForFooterInSection:]
-[ViewController tableView:titleForHeaderInSection:]
-[ViewController tableView:titleForFooterInSection:]方法
如下会调用三次tab
返回section的num
{
最后一个section
返回section的header
返回section的footer
返回section的行数
从第一个section开始
返回section的header
返回section的footer
返回section的行数
}co
section的数量 | 返回section的num{} | 返回section的num{}的调用顺序 | 最后调用header、footer的次数 |
1 | 三次 | 0 | 一组 |
2 | 三次 | 一、0 | 两组 |
3 | 三次 | 二、0、1 | 三组 |
4 | 三次 | 三、0、一、2 | 四组 |
5 | 三次 | 四、0、一、二、3 | 四组 |
6 | 三次 | 五、0、一、二、三、4 | 四组 |
问题一:为何到section数量4之后,最后调用header、footer的次数的次数都为4header
解决:在屏幕大小内绘制tableView,绘制多少内容,调用相应方法(若是一个section只露出一个header和几个cell,那么会先调用header,而后调用 tableView:cellForRowAtIndexPath:方法)ab
在设置的section内容以后,当前模拟器只能显示三个section(第三个section只有header露出来一点点,建立第一行cell和第二行cell,建立header和footer)
向下滑动,cell出现时,建立屏幕下下行cell(第一行cell出现,建立第三行cell)
section的倒数第二行cell出现时,不建立
section的最后一行cell的分界线出现时,建立下一个section的header
section最后一行cell出现时,先建立下一个section的第一行cell,而后建立section的footer
footer出现,不建立
下一个section的header出现时,建立下一个section的第二行cell
第一行cell出现时,建立第3行cell;
向上滑动,cell出现时,建立上一行cell(第二行cell出现,建立第一行cell)
第二行cell出现,建立第一行cell
第一行cell出现,不建立(plain模式,header还在头部)
header被拖动,footer将出现时,建立footer
footer出现,不建立
header将出现时,建立上一个section的最后一行cell,而后建立header
最后一行cell出现,建立倒数第二行;
问题二: 为何“返回section的num{}”这一组方法每次都是调用三次?