カスタムセルで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 の高さは変わりません。
: どこで間違いを犯していますか? 助けてください。
前もって感謝します