2017-07-13 14 views
0

uitableview autolayout余分な高さを引き起こすカスタムセル。別のプロジェクトで問題が発生した場所を検出できませんでした。 enter image description hereuitableview autolayout余分な高さを引き起こすカスタムセル

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 

    [_stubCell layoutSubviews]; 

    [self configureCell:_stubCell atIndexPath:indexPath]; 

    CGFloat height = [_stubCell.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height; 
    return height; 
} 


- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath { 
    return 40.f; 
} 

- (void)configureCell:(CCACustomCell *)cell atIndexPath:(NSIndexPath *)indexPath { 
    cell.customLabel.text = [_tableData objectAtIndex:indexPath.row]; 
    cell.customLabel.font = [UIFont fontWithName:@"Avenir-Light" size:16.0]; 
    cell.customLabel.textColor = UIColorFromRGB(0x32383B); 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    CCACustomCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath]; 
    [self configureCell:cell atIndexPath:indexPath]; 
    return cell; 
} 
+1

UILabelのテキスト文字列に、開始時に "\ n"の次の文字が含まれている場合は、それを確認してください。 –

+0

友人がいない、 "\ n"次の行の文字はありません – santanu

+0

@サンタヌン、これらはダイナミックセルかスタティックセルですか? –

答えて

0

あなたが_stubCellを作成する方法の詳細を提供してもらえますか?それは、ラベルにいくつかの制約が原因かもしれません。 文字列の高さを計算しようとしましたか?

+(CGFloat)calculateStringHeight:(NSString *)string WithFont:(UIFont *)font andSidePadding:(CGFloat)padding{ 

    CGRect rect = [string boundingRectWithSize:CGSizeMake([[UIScreen mainScreen]bounds].size.width - (2*padding), 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:font} context:nil]; 
    return rect.size.height; 
} 
0

このように、ラベルに必要な高さを返すことができます。説明ラベルの幅をLABEL_DESCRIPTION_WIDTHに渡す必要があります。

関連する問題