I'm using this popular approach for autoresizing content in UITableViewCell. And it's not working. All I get is this:
My app is a universal app and I'm using iOS 5 with a storyboard. Here's my code for .h file:
@interface SecondMasterViewController : UITableViewController
And for these two methods:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *identifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
cell.textLabel.numberOfLines = 0;
cell.textLabel.font = [UIFont fontWithName:@"Helvetica" size:17.0];
}
cell.textLabel.text = [self.mainCategories objectAtIndex:indexPath.row];
UIImage *myAwesomeCellImage;
myAwesomeCellImage = [UIImage imageNamed:
[NSString stringWithFormat:@"%@%@",
cell.textLabel.text,@".png"]];
cell.imageView.image = myAwesomeCellImage;
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellText = @"Go get some text for your cell.";
UIFont *cellFont = [UIFont fontWithName:@"Helvetica" size:17.0];
CGSize constraintSize = CGSizeMake(280.0f, MAXFLOAT);
CGSize labelSize = [cellText sizeWithFont:cellFont constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap];
return labelSize.height + 20;
}
What have I done wrong? I've tried different approaches and all of them don't work.
Thanks in advance!