当两个section的cell数量都为5的时候,方法的调用顺序:
-[ViewController numberOfSectionsInTableView:] -[ViewController tableView:titleForHeaderInSection:]-[ViewController tableView:titleForFooterInSection:]-[ViewController tableView:numberOfRowsInSection:], section = 1-[ViewController tableView:titleForHeaderInSection:]-[ViewController tableView:titleForFooterInSection:]-[ViewController tableView:numberOfRowsInSection:], section = 0
-[ViewController numberOfSectionsInTableView:]-[ViewController tableView:titleForHeaderInSection:]-[ViewController tableView:titleForFooterInSection:]-[ViewController tableView:numberOfRowsInSection:], section = 1-[ViewController tableView:titleForHeaderInSection:]-[ViewController tableView:titleForFooterInSection:]-[ViewController tableView:numberOfRowsInSection:], section = 0
-[ViewController numberOfSectionsInTableView:]-[ViewController tableView:titleForHeaderInSection:]-[ViewController tableView:titleForFooterInSection:]-[ViewController tableView:numberOfRowsInSection:], section = 1-[ViewController tableView:titleForHeaderInSection:]-[ViewController tableView:titleForFooterInSection:]-[ViewController tableView:numberOfRowsInSection:], section = 0
-[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:]
以下会调用三次
返回section的num{最后一个section返回section的header返回section的footer返回section的行数从第一个section开始返回section的header返回section的footer返回section的行数}
section的数量 返回section的num{}返回section的num{}的调用顺序最后调用header、footer的次数 1三次0一组 2三次1、0两组 3三次2、0、1三组 4三次3、0、1、2四组 5三次4、0、1、2、3四组 6三次5、0、1、2、3、4四组
问题一:为什么到section数量4以后,最后调用header、footer的次数的次数都为4
解决:在屏幕大小内绘制tableView,绘制多少内容,调用相应方法(如果一个section只露出一个header和几个cell,那么会先调用header,然后调用 tableView:cellForRowAtIndexPath:方法)
在设置的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{}”这一组方法每次都是调用三次?
转载于:https://www.cnblogs.com/LiuLady12138/p/4674423.html
相关资源:JAVA上百实例源码以及开源项目