iOS中动态cell的高度问题。cell中有一个固定高度的view,动态的label,求指教???

  • (void)setCellInfo:(PropertyClassifiedsModel *)model
    {
    //时间所在的view
    UIView *timeView = [[UIView alloc] init];
    [self.contentView addSubview:timeView];
    [timeView mas_makeConstraints:^(MASConstraintMaker *make) {
    make.top.equalTo(self.contentView.mas_top);
    make.left.equalTo(self.contentView.mas_left);
    make.size.mas_equalTo(CGSizeMake(Width, 54));
    }];

    UIImageView *ima = [[UIImageView alloc] init];
    [self.contentView addSubview:ima];

    self.notificationLabelContents = [[UILabel alloc] init];
    [ima addSubview:self.notificationLabelContents];

    ima.backgroundColor = [UIColor whiteColor];
    [ima mas_makeConstraints:^(MASConstraintMaker *make) {
    make.top.equalTo(timeView.mas_bottom);
    make.left.equalTo(self.notificationImageView.mas_right).offset(10);
    make.right.equalTo(self.contentView.mas_right).offset(-10);
    make.height.equalTo(self.notificationLabelContents).offset(20);
    }];
    //通知的具体内容
    // self.notificationLabelContents = [[UILabel alloc] init];
    // [ima addSubview:self.notificationLabelContents];
    [self.notificationLabelContents mas_makeConstraints:^(MASConstraintMaker *make) {
    make.top.equalTo(ima).with.offset(10);
    make.left.equalTo(ima.mas_left).with.offset(10);
    make.right.equalTo(ima).with.offset(-10);
    make.bottom.equalTo(ima).with.offset(-10);
    }];

    self.notificationLabelContents.textColor = [UIColor blackColor];
    self.notificationLabelContents.font = [UIFont systemFontOfSize:15];
    self.notificationLabelContents.text = model.notificationContents;
    self.notificationLabelContents.lineBreakMode = UILineBreakModeCharacterWrap;
    self.notificationLabelContents.numberOfLines = 0;
    CGSize size = [self.notificationLabelContents sizeThatFits:CGSizeMake(self.frame.size.width, MAXFLOAT)];

    self.notificationLabelContents.frame = CGRectMake(60, 44, size.width, size.height);
    NSLog(@"%f",size.height);

    CGRect cellRrect = self.contentView.frame;
    cellRrect.size.height = timeView.frame.size.height + ima.frame.size.height;
    self.contentView.frame = cellRrect;
    }
    直接写的预估高度
    self.PropertyClassifiedsTableView.rowHeight = UITableViewAutomaticDimension;
    self.PropertyClassifiedsTableView.estimatedRowHeight = 350;
    self.edgesForExtendedLayout = UIRectEdgeNone;

  • (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { PropertyClassifiedsTableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath]; return cell.frame.size.height; NSLog(@"%f",cell.frame.size.height); } 或者是我不写预估高度那段直接写上面这段也是不可以 效果图总是这样

图片说明