所以,它似乎heightForRowAtIndexPath是之前调用的cellForRowAtIndexPath。我目前正在使用cellForRowAtIndexPath计算每个单元格的高度(它们是可变高度,使用其中UILabel包含不同数量的文本。
如果在计算它的方法之前调用设置高度的方法,我对如何正确设置单元格的高度感到困惑。
我创建了一个 类别NSString和另一个类别UILabel,它们一起工作以UILabel形成正确的大小。问题是UITableViewCell包含这些标签的实例没有被调整大小,因此标签挂在每个标签的末端,与下面的标签重叠。
我知道我需要做的是使单元格的高度等于标签的高度,加上一些额外的边距空间,但我很困惑如何在计算标签高度之前设置高度。我可以在不使用的情况下设置某人的高度heightForRowAtIndexPath吗?或者如果没有,我可以计算其他地方的单元格的高度吗?我目前正在使用indexPath.row它来实现这一点,所以事先这样做会很棘手。这是我的 cellForRowAtIndexPath 的代码:
cellForRowAtIndexPath
- (UITableViewCell *) tableView: (UITableView *) tableView cellForRowAtIndexPath: (NSIndexPath *) indexPath
{
    FQCustomCell *_customCell = [tableView dequeueReusableCellWithIdentifier: @"CustomCell"];
    if (_customCell == nil) {
        _customCell = [[FQCustomCell alloc] initWithStyle: UITableViewCellStyleValue1 reuseIdentifier: @"CustomCell"];
    }
    _customCell.myLabel.text = [[_loadedNames objectAtIndex: indexPath.row] name];
    _customCell.myLabel.font = [UIFont fontWithName: @"FontA" size: 15.0f];
    UIView *backView = [[UIView alloc] initWithFrame: CGRectZero];
    backView.backgroundColor = [UIColor clearColor];
    _customCell.backgroundView = backView;
    _customCell.myLabel.frame = CGRectMake(5, 5, 265, 65);
    [_customCell.myLabel sizeToFitMultipleLines];
    return _customCell;
}