我正嘗試在UITableViewCells中創建多線動態UILabel。我有一個具有'評論'標籤的自定義UITableViewCell。單元格和標籤是在故事板中創建的。動態高度UILabel在離線移動後工作
我可以基於要存儲在UILabel中的多行數據(使用heightForRowAtIndexPath)正確計算UITableViewCells的高度。但是,我的問題在於實際的UILabel內容。 UILabel內容將僅在桌面加載時顯示1行數據。但是,一旦包含多行UILabel數據的單元移出屏幕並返回到屏幕上,則多行數據將以多行顯示在UILabel中。有沒有辦法解決這個問題,以便多行數據在表格加載時正確顯示?
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
CustomCell *cCell = (CustomCell *)cell;
MyObject = [myArray objectAtIndex:indexPath.row];
cCell.commentLabel.frame = CGRectMake(65.0f, 28.0f, 243.0f, 200.0f);
cCell.commentLabel.text = MyObject.multi_line_text_data;
cCell.commentLabel.adjustsFontSizeToFitWidth = NO;
cCell.commentLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
cCell.commentLabel.font = [UIFont systemFontOfSize:13.0];
cCell.commentLabel.lineBreakMode = NSLineBreakByWordWrapping;
cCell.commentLabel.numberOfLines = 0;
[cCell.commentLabel sizeToFit];
}
謝謝!
您是否使用自動佈局? – rdelmar
是的,我使用的是自動佈局 – user2312407