forkingdog / UITableView-FDTemplateLayoutCell

Template auto layout cell for automatically UITableViewCell height calculating
MIT License
9.93k stars 2.01k forks source link

这样添加约束应该没问题吧,但是计算出来的高度不对 #303

Closed GPX-NSlog closed 7 years ago

GPX-NSlog commented 7 years ago
    if (!_titleLabel) {
        _titleLabel = [UILabel labelWithFont:Font(15) textColor:[UIColor colorWithHexString:@"0x111111"]];
        _titleLabel.numberOfLines = 0;
        [self.contentView addSubview:_titleLabel];
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView).offset(16);
            make.top.equalTo(self.contentView).offset(10);
            make.right.equalTo(self.contentView.mas_right).offset(-16);
        }];
    }
    if (!_timeLabel) {
        _timeLabel = [UILabel labelWithFont:Font(14) textColor:[UIColor colorWithHexString:@"0x8C8D91"]];
        [self.contentView addSubview:_timeLabel];
        [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.titleLabel.mas_left);
            make.top.equalTo(self.titleLabel.mas_bottom).offset(7);
            make.bottom.equalTo(self.contentView.mas_bottom).offset(-10);
        }];
    }
    if (!_browseLabel) {
        _browseLabel = [UILabel labelWithFont:Font(14) textColor:[UIColor colorWithHexString:@"0x8C8D91"]];
        [self.contentView addSubview:_browseLabel];
        [self.browseLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.contentView.mas_left).offset(82);
            make.centerY.equalTo(self.timeLabel);
        }];
    }
weekwood commented 7 years ago

@GPX-NSlog, could you put more codes at least with the method name, and logs too.

GPX-NSlog commented 7 years ago

@weekwood

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.contentView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;

        if (!_titleLabel) {
            _titleLabel = [UILabel labelWithFont:Font(15) textColor:[UIColor colorWithHexString:@"0x111111"]];
            _titleLabel.numberOfLines = 0;
            [self.contentView addSubview:_titleLabel];
            [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(self.contentView).offset(16);
                make.top.equalTo(self.contentView).offset(10);
                make.right.equalTo(self.contentView.mas_right).offset(-16);
            }];
        }
        if (!_timeLabel) {
            _timeLabel = [UILabel labelWithFont:Font(14) textColor:[UIColor colorWithHexString:@"0x8C8D91"]];
            [self.contentView addSubview:_timeLabel];
            [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(self.titleLabel.mas_left);
                make.top.equalTo(self.titleLabel.mas_bottom).offset(7);
                make.bottom.equalTo(self.contentView.mas_bottom).offset(-10);
            }];
        }
        if (!_browseLabel) {
            _browseLabel = [UILabel labelWithFont:Font(14) textColor:[UIColor colorWithHexString:@"0x8C8D91"]];
            [self.contentView addSubview:_browseLabel];
            [self.browseLabel mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(self.contentView.mas_left).offset(82);
                make.centerY.equalTo(self.timeLabel);
            }];
        }

    }
    return self;
}

log

2017-04-28 15:21:56.266 xzap[57010:979681] ** FDTemplateLayoutCell ** calculate using system fitting size (AutoLayout) - 80
2017-04-28 15:21:56.268 xzap[57010:979681] ** FDTemplateLayoutCell ** calculate using system fitting size (AutoLayout) - 80
2017-04-28 15:21:56.270 xzap[57010:979681] ** FDTemplateLayoutCell ** calculate using system fitting size (AutoLayout) - 80
2017-04-28 15:21:56.273 xzap[57010:979681] ** FDTemplateLayoutCell ** calculate using system fitting size (AutoLayout) - 80
2017-04-28 15:21:56.275 xzap[57010:979681] ** FDTemplateLayoutCell ** calculate using system fitting size (AutoLayout) - 80
2017-04-28 15:21:56.277 xzap[57010:979681] ** FDTemplateLayoutCell ** calculate using system fitting size (AutoLayout) - 80
2017-04-28 15:21:56.279 xzap[57010:979681] ** FDTemplateLayoutCell ** calculate using system fitting size (AutoLayout) - 80
2017-04-28 15:21:56.282 xzap[57010:979681] ** FDTemplateLayoutCell ** calculate using system fitting size (AutoLayout) - 80
2017-04-28 15:21:56.284 xzap[57010:979681] ** FDTemplateLayoutCell ** calculate using system fitting size (AutoLayout) - 98
2017-04-28 15:21:56.286 xzap[57010:979681] ** FDTemplateLayoutCell ** calculate using system fitting size (AutoLayout) - 98
2017-04-28 15:21:56.967 xzap[57010:979681] ** FDTemplateLayoutCell ** calculate using system fitting size (AutoLayout) - 62
2017-04-28 15:21:56.970 xzap[57010:979681] ** FDTemplateLayoutCell ** calculate using system fitting size (AutoLayout) - 62
2017-04-28 15:21:57.218 xzap[57010:979681] ** FDTemplateLayoutCell ** calculate using system fitting size (AutoLayout) - 80
2017-04-28 15:21:57.220 xzap[57010:979681] ** FDTemplateLayoutCell ** calculate using system fitting size (AutoLayout) - 80
GPX-NSlog commented 7 years ago

delegate

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return [tableView fd_heightForCellWithIdentifier:gengCellID configuration:^(CHGengCell *cell) {
        cell.model = self.audioModels[indexPath.row];
    }];
}
GPX-NSlog commented 7 years ago

@weekwood thanks

setModel

- (void)setModel:(CHColimnistDetailModel *)model {
    _model = model;
    self.titleLabel.text = model.title;
    self.timeLabel.text = model.publish_time;
    self.browseLabel.text = [NSString stringWithFormat:@" %@人已浏览",model.browse];
}
weekwood commented 7 years ago

Please follow this link to use Masonry. Think it will help you to fix the issue. https://github.com/SnapKit/Masonry#where-should-i-create-my-constraints

Let me know if any more question.

weekwood commented 7 years ago

I am closing this now, let me know if any issue.