tableView代理方法执行顺序
来源:互联网 发布:萌牙电动牙刷 知乎 编辑:程序博客网 时间:2024/06/06 14:12
以前写table也没有关注那么多问题,但是今天突然发现不知道tableView的代理方法执行顺序了解的不是很清楚:于是打了断点来观察执行顺序: 点我下载示例哦
首先numberOfSectionsInTableView最先执行确定一个tableView有多少行section ---举例这里section = 3,每行row = 5
然后执行heightForHeaderInSection和heightForFooterInSection两次
执行numberOfRowsInSection,这里执行三次也是合理的,因为我们并不是每个section的row数都是相同的(题外,我表示并不知道为什么会这么来回执行三次呢)
下面就是绘制cell的函数和cell将要绘制的函数
最后是viewForHeaderInSection,返回每个section的头视图样式,(尾视图也是一样的哦),注意这里不管table上下拖动几次,有几个section就会执行几次,比如这里只会执行三次,下面我们来看三个例子:
1、当section= 1,数据源数组为空时,打印结果如下:
2015-09-11 15:24:17.853 testTableViewHeight[2179:146087] numberOfSectionsInTableView2015-09-11 15:24:17.854 testTableViewHeight[2179:146087] heightForHeaderInSection2015-09-11 15:24:17.854 testTableViewHeight[2179:146087] heightForHeaderInSection2015-09-11 15:24:17.854 testTableViewHeight[2179:146087] heightForFooterInSection2015-09-11 15:24:17.854 testTableViewHeight[2179:146087] heightForFooterInSection2015-09-11 15:24:17.854 testTableViewHeight[2179:146087] numberOfRowsInSection2015-09-11 15:24:17.854 testTableViewHeight[2179:146087] numberOfSectionsInTableView2015-09-11 15:24:17.854 testTableViewHeight[2179:146087] heightForHeaderInSection2015-09-11 15:24:17.854 testTableViewHeight[2179:146087] heightForHeaderInSection2015-09-11 15:24:17.854 testTableViewHeight[2179:146087] heightForFooterInSection2015-09-11 15:24:17.854 testTableViewHeight[2179:146087] heightForFooterInSection2015-09-11 15:24:17.854 testTableViewHeight[2179:146087] numberOfRowsInSection2015-09-11 15:24:17.855 testTableViewHeight[2179:146087] numberOfSectionsInTableView2015-09-11 15:24:17.856 testTableViewHeight[2179:146087] heightForHeaderInSection2015-09-11 15:24:17.872 testTableViewHeight[2179:146087] heightForHeaderInSection2015-09-11 15:24:17.872 testTableViewHeight[2179:146087] heightForFooterInSection2015-09-11 15:24:17.872 testTableViewHeight[2179:146087] heightForFooterInSection2015-09-11 15:24:17.873 testTableViewHeight[2179:146087] numberOfRowsInSection2015-09-11 15:24:17.873 testTableViewHeight[2179:146087] viewForHeaderInSection
2、当section = 1 ,数据源数组记录条数为30,也就是numberOfRowsInSection = 30,但是我一个页面只展示8条时打印结果如下:
2015-09-11 15:27:37.027 testTableViewHeight[2237:149952] numberOfSectionsInTableView2015-09-11 15:27:37.028 testTableViewHeight[2237:149952] heightForHeaderInSection2015-09-11 15:27:37.028 testTableViewHeight[2237:149952] heightForHeaderInSection2015-09-11 15:27:37.028 testTableViewHeight[2237:149952] heightForFooterInSection2015-09-11 15:27:37.028 testTableViewHeight[2237:149952] heightForFooterInSection2015-09-11 15:27:37.028 testTableViewHeight[2237:149952] numberOfRowsInSection2015-09-11 15:27:37.028 testTableViewHeight[2237:149952] numberOfSectionsInTableView2015-09-11 15:27:37.028 testTableViewHeight[2237:149952] heightForHeaderInSection2015-09-11 15:27:37.028 testTableViewHeight[2237:149952] heightForHeaderInSection2015-09-11 15:27:37.028 testTableViewHeight[2237:149952] heightForFooterInSection2015-09-11 15:27:37.029 testTableViewHeight[2237:149952] heightForFooterInSection2015-09-11 15:27:37.029 testTableViewHeight[2237:149952] numberOfRowsInSection2015-09-11 15:27:37.030 testTableViewHeight[2237:149952] numberOfSectionsInTableView2015-09-11 15:27:37.030 testTableViewHeight[2237:149952] heightForHeaderInSection2015-09-11 15:27:37.030 testTableViewHeight[2237:149952] heightForHeaderInSection2015-09-11 15:27:37.030 testTableViewHeight[2237:149952] heightForFooterInSection2015-09-11 15:27:37.030 testTableViewHeight[2237:149952] heightForFooterInSection2015-09-11 15:27:37.030 testTableViewHeight[2237:149952] numberOfRowsInSection2015-09-11 15:27:37.032 testTableViewHeight[2237:149952] cellForRowAtIndexPath2015-09-11 15:27:37.033 testTableViewHeight[2237:149952] willDisplayCell:forRowAtIndexPath:2015-09-11 15:27:37.033 testTableViewHeight[2237:149952] cellForRowAtIndexPath2015-09-11 15:27:37.034 testTableViewHeight[2237:149952] willDisplayCell:forRowAtIndexPath:2015-09-11 15:27:37.034 testTableViewHeight[2237:149952] cellForRowAtIndexPath2015-09-11 15:27:37.034 testTableViewHeight[2237:149952] willDisplayCell:forRowAtIndexPath:2015-09-11 15:27:37.034 testTableViewHeight[2237:149952] cellForRowAtIndexPath2015-09-11 15:27:37.034 testTableViewHeight[2237:149952] willDisplayCell:forRowAtIndexPath:2015-09-11 15:27:37.035 testTableViewHeight[2237:149952] cellForRowAtIndexPath2015-09-11 15:27:37.035 testTableViewHeight[2237:149952] willDisplayCell:forRowAtIndexPath:2015-09-11 15:27:37.035 testTableViewHeight[2237:149952] cellForRowAtIndexPath2015-09-11 15:27:37.035 testTableViewHeight[2237:149952] willDisplayCell:forRowAtIndexPath:2015-09-11 15:27:37.035 testTableViewHeight[2237:149952] cellForRowAtIndexPath2015-09-11 15:27:37.035 testTableViewHeight[2237:149952] willDisplayCell:forRowAtIndexPath:2015-09-11 15:27:37.035 testTableViewHeight[2237:149952] cellForRowAtIndexPath2015-09-11 15:27:37.036 testTableViewHeight[2237:149952] willDisplayCell:forRowAtIndexPath:2015-09-11 15:27:37.036 testTableViewHeight[2237:149952] viewForHeaderInSection
我们可以看到以下六个方法首先走了三次然后cellForRowAtIndexPath和willDisplayCell:forRowAtIndexPath:两个方法顺序交替执行,次数为展现在界面上的cell数量,因此我们要注意不要再这两个方法里面大量的创建对象,最好是cell为空的时候创建,其他的对象让cell复用机制来解决。---这里要注意,表格复用是指当cell的identifier相同是就会去表格的复用池中拿cell,并不代表不会走cell绘制这个方法
numberOfSectionsInTableView section数目
heightForHeaderInSection section头视图高度
heightForHeaderInSection section头视图高度
heightForFooterInSection section尾视图高度
heightForFooterInSection section尾视图高度
numberOfRowsInSection 每个section下行数
3、当section = 3 ,每个section下row为5展现结果如下:
执行顺序是:
2015-09-11 15:42:37.909 testTableViewHeight[2417:163537] numberOfSectionsInTableView2015-09-11 15:42:37.910 testTableViewHeight[2417:163537] heightForHeaderInSection2015-09-11 15:42:37.910 testTableViewHeight[2417:163537] heightForHeaderInSection2015-09-11 15:42:37.910 testTableViewHeight[2417:163537] heightForFooterInSection2015-09-11 15:42:37.910 testTableViewHeight[2417:163537] heightForFooterInSection2015-09-11 15:42:37.910 testTableViewHeight[2417:163537] numberOfRowsInSection2015-09-11 15:42:37.910 testTableViewHeight[2417:163537] heightForHeaderInSection2015-09-11 15:42:37.910 testTableViewHeight[2417:163537] heightForHeaderInSection2015-09-11 15:42:37.910 testTableViewHeight[2417:163537] heightForFooterInSection2015-09-11 15:42:37.910 testTableViewHeight[2417:163537] heightForFooterInSection2015-09-11 15:42:37.910 testTableViewHeight[2417:163537] numberOfRowsInSection2015-09-11 15:42:37.910 testTableViewHeight[2417:163537] heightForHeaderInSection2015-09-11 15:42:37.910 testTableViewHeight[2417:163537] heightForHeaderInSection2015-09-11 15:42:37.910 testTableViewHeight[2417:163537] heightForFooterInSection2015-09-11 15:42:37.911 testTableViewHeight[2417:163537] heightForFooterInSection2015-09-11 15:42:37.911 testTableViewHeight[2417:163537] numberOfRowsInSection以上方法保持这个顺序走了三遍,然后就是cellForRowAtIndexPath和willDisplayCell:forRowAtIndexPath:两个方法顺序交替执行了8次(因为出现在界面上8行cell)最后viewForHeaderInSection和viewForFooterInSection交替执行了两次(因为这里只展现出两行section)
2015-09-11 16:27:32.767 testTableViewHeight[3039:210959] viewForHeaderInSection2015-09-11 16:27:32.768 testTableViewHeight[3039:210959] viewForFooterInSection2015-09-11 16:27:32.768 testTableViewHeight[3039:210959] viewForHeaderInSection2015-09-11 16:27:32.768 testTableViewHeight[3039:210959] viewForFooterInSection
0 0
- tableView代理方法执行顺序
- UIScrollView代理方法执行顺序
- tableView中几个代理方法调用的顺序
- 为什么TableView 的代理方法cellForRowAtIndexPath 不执行问题
- viewController 和 tableView 相关方法执行顺序及作用
- ios中tableview中的方法的执行顺序
- tableView - 常用代理方法
- UItableview全部属性、方法以及代理方法执行顺序
- UITableView的全部属性、方法以及代理方法执行顺序
- UITableView的全部属性、方法以及代理方法执行顺序
- UITableView的全部属性、方法以及代理方法执行顺序
- XZ_iOS之UITableView的代理方法的执行顺序
- TableView代理方法详解(一)
- tableview自定义空间代理方法
- TableView 代理方法详细解释
- 一、IOS程序执行顺序、APPdelegate代理方法执行顺序、ViewController 生命周期
- TableView的添加删除执行顺序
- iOS中tableview的执行顺序
- 反编译的问题
- Perl 特殊字符
- ipad/iphone兼容小技巧
- mysql 语句
- 某电网首套调度软交换设备成功投运
- tableView代理方法执行顺序
- Rails_安装_报错_解决_Could not find a JavaScript runtime_(ExecJS::RuntimeUnavailable)
- [leetcode] Isomorphic Strings
- openwrt多线程程序交叉编译时候出现错误解决方法
- 功能测试与自动化测试到底谁高级?
- 随机数
- Java学习篇之---文件路径中的空格
- 与DNSPod携手共创域名辉煌!
- C#学习第七天 面向对象、类、对象的概念