0
我有一个名为Comment的子类UITableViewCell,它有一个包含一些相关信息的UILabel。这些信息的长度各不相同,因此我只能为UILabel设置合适的高度。使UITableViewCells动态的问题
我已经尝试使单元格动态,但UILabel要么溢出单元格(y轴)或单元格太大。
请你能告诉我哪里出错了吗?
tableView... cellForRowAtIndexPath...
[cell->commentText setLineBreakMode:UILineBreakModeWordWrap];
[cell->commentText setMinimumFontSize:14];
[cell->commentText setNumberOfLines:0];
[cell->commentText setFont:[UIFont systemFontOfSize:14]];
NSString *text = [cell->commentText text];
CGSize constraint = CGSizeMake(320, 20000.0f);
CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:14] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
[cell->commentText setText:text];
[cell->commentText setFrame:CGRectMake(20, 40, 280, MAX(size.height, 125))];
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *text = [[[comments objectAtIndex:indexPath.row] body] stringByStrippingHTML];
CGSize constraint = CGSizeMake(320, 20000.0f);
CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:14] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
CGFloat height = MAX(size.height, 125);
return height + 20;
}