表视图单元格的高度计算为零

时间:2014-11-28 02:23:14

标签: ios objective-c uitableview autolayout heightforrowatindexpath

UITableViewCell我的单元格的高度由于某种原因计算为零。

这是我目前所拥有的:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    id model = self.Model[indexPath.row];

    if ([model isKindOfClass:[FR self]]) {
        ListTableViewCell *cellOne = [tableView dequeueReusableCellWithIdentifier:@"1Cell" forIndexPath:indexPath];
        if (!cellOne) {
            cellOne = [[ListTableViewCell alloc] init];

            FR *fD = (FR *)model;
            NSString *title = [NSString stringWithFormat:@"%@", fD.title];
            NSString *dateString = [self timeSincePublished:fD.pubDate];
            NSString *description = [self removeHTMLTags:fD.description];
            NSString *link = [NSString stringWithFormat:@"%@", fD.link];

            cellOne.labelHeadline.text = title;
            cellOne.labelDescription.text = description;
            cellOne.labelPublished.text = dateString;
        }

        // Make sure the cell's frame is updated
        [cellOne setNeedsLayout];
        [cellOne layoutIfNeeded];

        CGFloat heightOne = [cellOne.contentView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
        return heightOne + 2;

    } else if ([model isKindOfClass:[D self]]) {

    // more code
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    id model = self.Model[indexPath.row];

    if ([model isKindOfClass:[FR self]]) {

        FR *fD = (FR *)model;

        ListTableViewCell  *1Cell = [tableView dequeueReusableCellWithIdentifier:@"1Cell"];

        if (!1Cell) {
            1Cell = [[ListTableViewCell alloc] init];

            FR *fD = (FR *)model;
            NSString *title = [NSString stringWithFormat:@"%@", fD.title];
            NSString *dateString = [self timeSincePublished:fD.pubDate];
            NSString *description = [self removeHTMLTags:fD.description];

            1Cell.labelHeadline.text = title;
            1Cell.labelDescription.text = description;
            1Cell.labelPublished.text = dateString;

        }

        return 1Cell;

    }

    // more code
}

我不确定为什么heightOne返回零,当我断点查看heightOne是什么值时。

我正在使用AutoLayout。

有什么想法吗?谢谢!如果需要,会发布额外的代码,谢谢!

0 个答案:

没有答案