Background: This is a few days to do the project, but also encountered the cell's adaptive height problem
First we have to know UITableViewCell agent execution order, in IOS7 appeared an agent method called: Tableview:estimatedheightforrowatindexpath:, First we need to know that the cell height must be calculated when using UITableViewCell, so what if the cell's content is dynamic? At this point we have to return to the height of the dynamic, which is back to the problems we encountered in the project. Knowing this, we must then know the order in which Uitableviewde's proxy methods are executed, respectively:
You can see that the heightforrowatindexpath is executed before executing the Cellforrowatindexpath, that is, the Heightforrowatindexpath is called when the cell does not exist. This is not enough to meet the project requirements until the new API IOS7 appears, which is said above: Tableview:estimatedheightforrowatindexpath:, this proxy method back to the cell's estimate height, if this method is implemented, It also means that the execution order of the UITableView agent method is changed, such as:
A little tidying up will give you the following conclusions:
- First TableView will get the estimated height of each cell (Estimatedheightforrow ...) to the agent first. method), and take this height to calculate the range that the entire tableview should show
- Based on the estimated height of each row, the number of cells displayed on one screen is calculated, and the cells are first called cellforrow ... method) to draw
- Get the cell's true height when drawing, and then place it in Heightforrow ... method, take it with Tabelview.
- When the screen scrolls (with the cell entering the screen), the method of drawing and getting the true height is still called.
In short, it is estimated that the height is used to let the TableView heart have a bottom, the cell first drawn out, but finally the actual cell height will be from Heightforrow ... method to obtain the.
Reference documents:
Wen/coderao (author of Jane's book)
Original link: http://www.jianshu.com/p/6ab92579fcf1
Copyright belongs to the author, please contact the author to obtain authorization, and Mark "book author".
Cell Adaptive for IOS UITableView