hahaha7788 2015-12-31 03:07 采纳率: 0%
浏览 1779

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;

  • 写回答

2条回答 默认 最新

  • hahaha7788 2015-12-31 03:11
    关注
    • (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); } 或者是我不写预估高度那段直接写上面这段也是不可以 效果图总是这样
    评论

报告相同问题?

悬赏问题

  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建