Okay..so before you mark this is as a repeated question, read it. I ve implemented the code given by CIMGF for dynamic resizing of UITableViewCell
. It worked for the first time around but does not seem to work now. Strange, right?
Anyway, here are the code snippets:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
{
NSString *text = [[buzzList objectAtIndex:[indexPath row]] objectForKey:@"description"];
CGSize constraint = CGSizeMake(260, 20000.0f);
CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
CGFloat height = size.height;
return height +25 +(CELL_CONTENT_MARGIN * 2);
}
和 CellForRowAtIndexPath
的相应代码是:
[cell.descriptionLabel setLineBreakMode:UILineBreakModeWordWrap];
[cell.descriptionLabel setMinimumFontSize:FONT_SIZE];
[cell.descriptionLabel setNumberOfLines:0];
[cell.descriptionLabel setFont:[UIFont systemFontOfSize:FONT_SIZE]];
CGSize constraint = CGSizeMake(CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2), 20000.0f);
CGSize size = [[[buzzList objectAtIndex:indexPath.row] objectForKey:@"description"] sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
cell.descriptionLabel.text=[[buzzList objectAtIndex:indexPath.row] objectForKey:@"description"];
CGRect rect=CGRectMake(45, 20, 260, size.height);
[cell.descriptionLabel setFrame:rect];
值 45,20,260 由我设定,以获取单元格中文本的起始点和宽度的确切位置。 值是正确的, 无需修改。 但是, 我执行代码时, 我能得到单元格的正确高度( 根据文本可同步调整) BUT
descriptionLabel
显示最多2行文本。 它在此之后截断文本 。 () :