iOS UITableView: what's the different between “cellForRowAtIndexPath” and “willDisplayCell: forRowAtIndexPath:”

前端 未结 6 985
别那么骄傲
别那么骄傲 2020-11-30 01:06

Just as the question\'s title mentions: What\'s the difference between \"cellForRowAtIndexPath\" and \"willDisplayCell: forRowAtIndexPath

6条回答
  •  天涯浪人
    2020-11-30 01:37

    I faced an issue with cell configuration in willDisplayCell: when used autolayout and UITableViewAutomaticDimension. The heights of reused cells didn't calculate properly. Printing methods in NSLog shows that willDisplayCell: is called after heightForRowAtIndexPath: (tested on iOS 10.2 simulator)

    cellForRowAtIndexPath:  {length = 2, path = 1 - 0}
    heightForRowAtIndexPath:  {length = 2, path = 1 - 0}
    heightForRowAtIndexPath:  {length = 2, path = 1 - 0}
    willDisplayCell:  {length = 2, path = 1 - 0}
    cellForRowAtIndexPath:  {length = 2, path = 1 - 1}
    heightForRowAtIndexPath:  {length = 2, path = 1 - 1}
    heightForRowAtIndexPath:  {length = 2, path = 1 - 1}
    willDisplayCell:  {length = 2, path = 1 - 1}
    

    I think this was the reason, because problem has gone after placing configuration code in cellForRowAtIndexPath:

    P.S. There is an opposite article to the link and quote posted by @iTSangar: https://tech.zalando.com/blog/proper-use-of-cellforrowatindexpath-and-willdisplaycell/

提交回复
热议问题