Question
How can you determine when a table view is performed, drawing cells?
Problem
I got two labels inside the contentView of a UITableViewCell. The size of these labels is dynamic. I was able to do this by subclassing the UITableViewCell, in the drawRect method I adjust the frames of two labels depending on their contents. Now I want to align all other marks.
My thoughts are steps away
- Define the content in the table view and load it automatically.
- Go through the table view cells and determine the x position of the second label in the UITableViewCell, which is the farthest.
- Save this x position, and when any cell is drawn, use this x position to place the second label.
The problem is that if I use the following code:
for (int row = 0; row < [self.tableView numberOfRowsInSection:section]; row++) { UITableViewCustomCell *cell = (UITableViewCustomCell *)[self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:row inSection:0]]; NSLog ([cell.labelTwo description]); }
The second label has not yet been drawn, which means that I cannot determine the size of the frame and, therefore, cannot find the correct x position to align all the second labels.
I tried to subclass UITableViewController and look at events such as viewDidLoad and viewDidAppear, unfortunately, the cells are not drawn in these events yet.
What I want...
I want the table view to draw cells at least once so that I can define label sizes inside the table view cell. I decided to do this by going through all the cells using cellForRow, but although it successfully returns the cell, the content is not drawn, but that means the frame remains at zero width.
Anyone have a solution?
Thanks in advance,
Mark
iphone uitableview drawrect
Mark
source share