Download UILabel from the storyboard, cannot change frame in cellForRowAtIndexPath

I am developing an application for iOS6. I have dynamic cells initialized in a storyboard that contains some UILabelsand some UIImageViews. Height for them can be changed "on the fly." My question is when I change the frame to cellForRowAtIndexPathas follows:

contentText = (UILabel *)[cell viewWithTag:TAG_TOPIC_CONTENT_TEXT];

CGFloat height = [[self.contentHeights objectAtIndex:[indexPath row]] floatValue];

contentText.frame = CGRectMake(CELL_TOPIC_CONTENT_X, CELL_TOPIC_CONTENT_Y, CELL_CONTENT_WIDTH, height);

The height of the contentText displayed on the screen is UILabelstill the same as what I initialized in the Storyboard. The modification seems to not work. If I update UITableViewmine, the height of the contentText will be fixed, how to solve the problem? Thanks in advance!

+5
source share
3 answers

tableView:willDisplayCell:forRowAtIndexPath:. , . , !

0

, UITableViewCell layoutSubviews:

- (void)layoutSubviews {
  [super layoutSubviews];

  // modify frames here
}
0

I know his disappointment, but I also did not find a solution for this. Instead, I found a workaround for everything to be done as I expect them to work.

I deleted "AutoLayout" (checkbox in storyboard)

Then:

[self.label setText:@"Labeltext"];
[self.label setBackgroundColor:[UIColor orangeColor]];// just to make the frame visible
[self.label setNumberOfLines:0];
[self.label sizeToFit];

works like a charm, but also:

self.label.frame = CGRectMake(0, 0, 50, 50);

So, if you do not need AutoLayout (for me this is the first thing that I will take off) get rid of it.

0
source

All Articles