Cell adaptability of iOS UITableview, uitableviewcell
Background: In the past few days, we have encountered the cell adaptive height problem.
First, we must know the proxy execution sequence of UITableViewcell. In iOS7, a proxy method named tableView: estimatedHeightForRowAtIndexPath: appears. First, we must know that the height of the cell must be calculated when UITableViewcell is used, what if the cell content is dynamic? At this time, we must dynamically return the height, which is back to the problems encountered in our project. With this in mind, we need to know the execution sequence of the UITableViewde proxy method, such:
We can see that heightForRowAtIndexPath is executed before cellForRowAtIndexPath is executed. That is to say, heightForRowAtIndexPath is called when the cell does not exist, which cannot meet the project requirements, until the new API appears in iOS7, this is what we mentioned above: tableView: estimatedHeightForRowAtIndexPath:. This proxy method returns an estimated height to the cell. If this method is implemented, this means that the execution sequence of the proxy method of UITableView is changed, for example:
A little bit of sorting will draw the following conclusions:
Simply put, the height is estimated to give tableView a bottom picture and draw the cell first, but the actual cell height will still be obtained from the heightForRow... method.
References:
Text/CoderAO (simplified author)
Link: http://www.jianshu.com/p/6ab92579fcf1
Copyright belongs to the author. For reprinted content, contact the author for authorization and mark "author of simplified book ".