forkingdog / UITableView-FDTemplateLayoutCell

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

Masonry布局;subCell继承superCell的问题 #391

Open 304164084 opened 5 years ago

304164084 commented 5 years ago

项目中聊天cell; 每个cell都有时间label。但是label依据某些规则有时显示有时不显示;但是每个cell都要有这个控件; 所以将其写在一个基类的cell中;其他子cell继承自他并继续写布局

/* root cell /

/* sub cell /

// head img view 默认为客服头像 UIImage *img = [UIImage imageNamed:@"xxxx"]; _headImageView = [[UIImageView alloc] initWithImage:img];

[self.contentView addSubview:_headImageView];
[_headImageView mas_makeConstraints:^(MASConstraintMaker *make) {
      // 这里的timeContainerView 就是继承上面的rootcell 来的,相当于接着super的 setupViews接着写
    make.top.mas_equalTo(self.timeContainerView.mas_bottom).offset(16.f);
    make.leading.mas_equalTo(self.contentView.mas_leading).offset(8.f);
    make.size.mas_equalTo(img.size);
}];

// 聊天气泡
_chatBubbleView = [UIView new];

[self.contentView addSubview:_chatBubbleView];
[_chatBubbleView mas_makeConstraints:^(MASConstraintMaker *make) {
    make.top.mas_equalTo(self.timeContainerView.mas_bottom).offset(16.f);
    make.leading.mas_equalTo(self.headImageView.mas_trailing).offset(8.f);
    make.bottom.mas_equalTo(self.contentView);
}];

}

/* cell 缓存代码 /

我之前是用的系统的自动计算高度的方法 可以正常布局。 //- (CGFloat)tableView:(UITableView )tableView estimatedHeightForRowAtIndexPath:(NSIndexPath )indexPath { return UITableViewAutomaticDimension; }

但是考虑到没有高度缓存。所以想替换成您这个。

期待您的回复!~