我已经用自定义单元格实现了 UITableView,
我想要做的是,我想UITableViewCell
根据文本长度改变高度,(动态高度)
这是我的代码片段,
#define FONT_SIZE 14.0f
#define CELL_CONTENT_WIDTH 320.0f
#define CELL_CONTENT_MARGIN 10.0f
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
{
NSString *text = [DescArr objectAtIndex:[indexPath row]];
CGSize constraint = CGSizeMake(CELL_CONTENT_WIDTH - (CELL_CONTENT_MARGIN * 2), 20000.0f);
CGSize size = [text sizeWithFont:[UIFont systemFontOfSize:FONT_SIZE] constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
CGFloat height = MAX(size.height, 55.0);
return height;
}
高度UITableViewCell
变化正确,但 CustomCell 的高度没有变化,
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"BTSTicketsCellIdentifier";
CRIndCoupnCell *cell = (CRIndCoupnCell *)[tblDescriptn dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CRIndCoupnCell" owner:self options:nil];
for (id oneObject in nib) if ([oneObject isKindOfClass:[CRIndCoupnCell class]])
cell = (CRIndCoupnCell *)oneObject;
}
NSLog(@"cell.frame.size.height=%f",cell.frame.size.height);
cell.lblleft.text=[arr objectAtIndex:indexPath.row];
cell.lblRight.text=[DescArr objectAtIndex:indexPath.row];
return cell;
}
我的日志显示cell.frame.size.height=100.0
在所有行中。CustomCell 的高度不会改变。
: 我在哪里犯错了?请帮忙。
提前致谢