I'm trying to calculate the height for a UITableViewCell so I've defined a class method that looks like this
+ (CGFloat)heightWithText:(NSString *)text
{
SizingLabel.text = text;
[SizingLabel sizeThatFits:CGSizeMake(LABEL_WIDTH, CGFLOAT_MAX)];
return (TOP_MARGIN + SizingLabel.frame.size.height + BOTTOM_MARGIN);
}
I've defined SizingLabel like this:
+ (void)initialize
{
SizingLabel = [[UILabel alloc] initWithFrame:CGRectZero];
SizingLabel.numberOfLines = 0;
SizingLabel.lineBreakMode = NSLineBreakByWordWrapping;
}
However, if i stick a breakpoint in the -heightWithText: method, i notice that the dimensions of SizingLabel never change and i thus get an incorrect value. Why is that?