Cannot change frame of a UILabel in a UITableViewCell when first appearing (using Autolayout)

autolayout, ios, layoutsubviews, objective-c, uitableview

Solution

In xib, go to first tab, under Interface Builder Document , uncheck use Auto Layout box.

Problem

I have a prototype cell inside my `UITableView` which contains a `UILabel`. I want to dynamically change the size of the label (and the cell) depending on the size of the text in the label. I create the prototype cell in `cellForRowAtIndexPath` like this: ``` static NSString *CellIdentifier = @"ProgramDetailCell"; ProgramDetailCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; cell.descriptionLabel.text = self.program.subtitle; return cell; ``` Then my `ProgramDetailCell` has the following implementation: ``` @implementation ProgramDetailCell - (void)layoutSubviews { [super layoutSubviews]; [self.descriptionLabel sizeToFit]; } @end ``` The first time the cell is displayed, `layoutSubviews` is called, but the `descriptionLabel` does not get resized. However, if I scroll down the table and back up again, the "reused" cell appears with the label correctly resized! Why does it not work the first time the cell is displayed - and what do I need to do to fix it. Thanks in advance!

Original source