I am trying to get a shortcut in a cell for the correct size, regardless of device or orientation. I can set the line height correctly. I can also set the height of the labels in cellForRowAtIndexPath and check this in my logs. But by the time it reaches willDisplayRowAtIndexPath , the height of the label has changed, but only when the cell does not have a width of 320 pixels.
Here is my code -
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"CustomCellIdentifier"; CustomInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil){ cell = [[CustomInfoCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier]; NSArray *objects = [[NSBundle mainBundle] loadNibNamed:@"CustomInfoCell" owner:self options:nil]; cell = objects[0]; }
In willDisplayRowAtIndexPath I also print label information. One line prints here -
2013-03-24 18:33:44.009 Bridge Alert[57793:1e503] labelWidth:728.000000 2013-03-24 18:33:44.010 Bridge Alert[57793:1e503] labelsize:713.000000,76.000000 2013-03-24 18:33:44.010 Bridge Alert[57793:1e503] Pre: <UILabel: 0xad3eaf0; frame = (20 20; 280 21); text = 'Detail'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x17372eb0>> 2013-03-24 18:33:44.011 Bridge Alert[57793:1e503] Post: <UILabel: 0xad3eaf0; frame = (20 22; 728 76); text = 'Detail'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x17372eb0>> 2013-03-24 18:33:44.011 Bridge Alert[57793:1e503] Text set: <UILabel: 0xad3eaf0; frame = (20 22; 728 76); text = 'A bridge is considered "f...'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x17372eb0>> 2013-03-24 18:33:44.014 Bridge Alert[57793:1e503] Display:<UILabel: 0xad3eaf0; frame = (20 20; 728 190); text = 'A bridge is considered "f...'; clipsToBounds = YES; opaque = NO; autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x17372eb0>>
As you can see, the size of the label is changed using the display. I assume that the height is recalculated somehow, based on whether the cell was 320 pt wide, which is the inline width of the UITableViewCell.
How can I assign a label correctly?
source share