ios - 单元格高度无法正常工作

标签 ios iphone objective-c

我使用以下代码动态更改单元格高度。但它没有显示任何内容。谁能帮我做到这一点。

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(!self.customCell){
        self.customCell = [self.tableView dequeueReusableCellWithIdentifier:@"CustomCell"];
    }

    //Cell configuration
    self.customCell.title.text = vendor[indexPath.row];

    int quoteIndex = indexPath.row % [vendor count];
    self.customCell.description.text = message[quoteIndex];

    //Cell Layout
    [self.customCell layoutIfNeeded];

    //Height of cell
    CGFloat height = [self.customCell systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
    //    CGFloat height = 240;

    return height;
}

最佳答案

在自定义单元格中,描述标签 - 设置行数 = 0

[Label SizeToFit] 会帮助你。
此代码可能对您有所帮助。

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(!self.customCell){
        self.customCell = [self.tableView dequeueReusableCellWithIdentifier:@"CustomCell"];
    }

    //Cell configuration
    self.customCell.title.text = vendor[indexPath.row];

    int quoteIndex = indexPath.row % [vendor count];
    self.customCell.description.text = message[quoteIndex];

    [self.customCell.description sizeToFit];

    float height = (CGRectGetMaxY(self.customCell.description.frame) + 5);
    return height;
}

谢谢

关于ios - 单元格高度无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24607319/

相关文章:

iphone - 如何将 iPhone 音频路由到蓝牙耳机

ios - UIKit 导入了什么,我如何找到?

ios - 无法使用自动布局正确构建 UIScrollView

iphone - 保存证书签名请求以供多次使用是否安全?

iphone - 如何在 iPhone 中解析 xml,

iphone - 使用简单的 NSMutableURLRequest 获取 facebook 个人资料图片

ios - 大型 uitableview(1000 行)在 reloadData() 上卡住

objective-c - 激活热键快捷记录器

ios - 何时使用dispatch_get_main_queue

ios - NSXMLParser 找不到结束标记