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;
}