Great question! In fact, I did something similar in some of my applications I can think of a couple of alternatives, but all of these are along the same theme. You could also just to use sizeWithFont: inside of heightForRowAtIndexPath: and do away with the array.In that case, you might take a performance hit for recalculating the size each time, if that operation is expensive You could do "lazy loading" of the cellHeights array inside of heightForRowAtIndexPAth: so it might look something like this: (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { if (cellHeights objectAtIndex:indexPath.
Row == nil) { ... calculate height and store it in the array at the correct index... } return cellHeights objectAtIndex:indexPath. Row floatValue; } The advantage I am thinking of here is that you will only calculate the heights for cells that are definitely going to be loaded. If you do the calculation in viewWillAppear I guess you end up doing it for every cell, regardless of whether it is displayed?
Finally, you could put the size in your data model itself. If it is, for example, an array of strings, you could make a class that has two properties: a string and a "representationSize" property. Then you can recalculate the size of the string each time the value of the string is changed.
Then, there would just be one array, not two, that maps onto your data source, filled with a data class containing both the string and display size of the string, and the value would be calculated when the string changes, not at all once when the view appears Anyway, I would love to hear some comments about these various approaches.
Great question! In fact, I did something similar in some of my applications. I can think of a couple of alternatives, but all of these are along the same theme.
You could also just to use sizeWithFont: inside of heightForRowAtIndexPath: and do away with the array. In that case, you might take a performance hit for recalculating the size each time, if that operation is expensive. You could do "lazy loading" of the cellHeights array inside of heightForRowAtIndexPAth: so it might look something like this: - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { if (cellHeights objectAtIndex:indexPath.
Row == nil) { ... calculate height and store it in the array at the correct index... } return cellHeights objectAtIndex:indexPath. Row floatValue; } The advantage I am thinking of here is that you will only calculate the heights for cells that are definitely going to be loaded. If you do the calculation in viewWillAppear, I guess you end up doing it for every cell, regardless of whether it is displayed?
Finally, you could put the size in your data model itself. If it is, for example, an array of strings, you could make a class that has two properties: a string and a "representationSize" property. Then you can recalculate the size of the string each time the value of the string is changed.
Then, there would just be one array, not two, that maps onto your data source, filled with a data class containing both the string and display size of the string, and the value would be calculated when the string changes, not at all once when the view appears. Anyway, I would love to hear some comments about these various approaches.
Too bad. I was hoping for more responses as well. Thanks for your input!
– galacticfury Sep 30 at 15:07.
Matthew's idea of putting the height in the data model sounds interesting. Here's another answer that proposes a very similar solution: How can I do variable height table cells on the iPhone properly?
You could also just to use sizeWithFont: inside of heightForRowAtIndexPath: and do away with the array. In that case, you might take a performance hit for recalculating the size each time, if that operation is expensive. The advantage I am thinking of here is that you will only calculate the heights for cells that are definitely going to be loaded.
If you do the calculation in viewWillAppear, I guess you end up doing it for every cell, regardless of whether it is displayed? Finally, you could put the size in your data model itself.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.