I need to access my cell in the table from tableView:heightForRowAtIndexPath:
since I want to use the data I have ion the custome cell for the height calculations.
The only way I have found to get my cells is to call tableView:cellForRowAtIndexPath:
The problem with that is that calling tableView:cellForRowAtIndexPath:
is actually 开发者_高级运维creating the cells and than doing nothing with them. when the same cell will need to be used for drawing purpose it will be created again. So for the same index the cell is created twice.
So I am wondering is there a more effective way to do it. Thanks for the help.
You don't have access to the cell in this method because it does not exist yet. tableView:heightForRowAtIndexPath:
is called before you create the cell in tableView:cellForRowAtIndexPath:
.
But it should not matter because you should not hold model information in the cell objects. The cells are only views and you should always hold the all the data you need to construct a cell in your model.
Typically, you choose which cell to return from tableView:cellForRowAtIndexPath:
based on your data and the index path.
Thus, you can use that same data and index path to determine which cell height to return in tableView:heightForRowAtIndexPath:
.
精彩评论