我已实施的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的高度不会改变。
: 我在哪里犯错?请帮忙。
预先感谢
确保您使用的是定制的小区标识是正确的 –
是的,这是正确的数据来了,但细胞的高度是不妥当的。 – Krunal
可以在这个CGFloat height = MAX(size.height,55.0)中打印高度; –