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 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)