UITableView delegate/dataSource方法執行順序

第一輪:

 

1、numberOfSectionsInTableView    :假如section=2,此函數只執行一次,假如section=0,函數不執行,默認爲1

 

2、heightForHeaderInSection  ,執行兩次,此函數執行次數爲section數目

 

3、heightForFooterInSection  ,函數屬性同上,執行兩次

 

4、numberOfRowsInSection    ,此方法執行一次

 

5、heightForHeaderInSection    ,此方法執行了兩次,我其實有點困惑爲什麼這裏還要調用這個方法

 

6、heightForFooterInSection  ,此方法執行兩次,

 

7、numberOfRowsInSection,執行一次

 

8、heightForRowAtIndexPath  ,行高,先執行section=0,對應的row次數

 

第二輪:

 

1、numberOfSectionsInTableView ,一次

 

2、heightForHeaderInSection  ,section次數

 

3、heightForFooterInSection    ,section次數

 

4、numberOfRowsInSection    ,一次

 

5、heightForHeaderInSection  ,執行section次數

 

6、heightForFooterInSection,執行section次數

 

7、numberOfRowsInSection,執行一次

 

8、heightForRowAtIndexPath,行高,先執行一次

 

9、cellForRowAtIndexPath

 

10、willDisplayCell

 

然後8、9、10依次執行直到所有的cell被描畫完畢

 

補充一下 : 設置tableview預估高度estimateHeight   啓用預估高度之後:先調用estimatedHeightForRowAtIndexPath返回代理估計高度,然後再根據預估高度調用cellForRowAtIndexPath渲染cell內容,同時計算真實高度,最後再調用heightForRowAtIndexPath拿到計算的真實高度 顯示

iOS11 默認開啓可預估高度, iOS 11 之前開啓預告也是 先9 後8 只是iOS11 之前預估默認關閉。關了預估高, 8 =》 9 self.tableView.estimatedRowHeight = 0;  關了預估高, iOS11 默認開啓。  不管iOS幾, 開啓預估高 都是 9 -》8    關閉都是 8-》9     

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章