I have a cell prototype inside my UITableView that contains a UILabel . I want to dynamically resize the label (and cell) depending on the size of the text in the label.
I create a prototype cell in cellForRowAtIndexPath as follows:
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 a cell is layoutSubviews , layoutSubviews is layoutSubviews , but descriptionLabel does not change. However, if I scroll down the table and back up again, the "reused" cell is displayed with the label correctly changed!
Why it doesnโt work on the first display of the cell - and what I need to do to fix it.
Thanks in advance!
ios objective-c uitableview autolayout layoutsubviews
theDuncs
source share