forkingdog / forkingdog/UITableView-FDTemplateLayoutCell
Masonry布局;subCell继承superCell的问题
- Dominant language
- Objective-C
- Stars
- 9.9k
- Forks
- 2k
- PR merge metrics
- No merged PRs in 30d
Description
项目中聊天cell; 每个cell都有时间label。但是label依据某些规则有时显示有时不显示;但是每个cell都要有这个控件;
所以将其写在一个基类的cell中;其他子cell继承自他并继续写布局
/** root cell */
- (void)setupViews
{
_timeContainerView = [UIView new];
[self.contentView addSubview:_timeContainerView];
[_timeContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.contentView).offset(0.f); // 显示时 间距顶部24pt
make.centerX.mas_equalTo(self.contentView);
}];
}
/** sub cell */
- (void)setupViews
{
[super setupViews];
// 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 heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
Entity *entity = self.dataSource[indexPath.row];
return [tableView fd_heightForCellWithIdentifier:SubCellID cacheByIndexPath:indexPath configuration:^(SubCell *cell) {
cell.entity = entity;
}];
}
**以上是一个纯文本的聊天cell样式**
出现的问题:
cell出现的时候布局错乱。感觉是因为没有去读取父类那个时间label的布局。 然后再次刷新cell(比如reloadData)的时候。布局就会正常。
请问应该怎么解决?
我之前是用的系统的自动计算高度的方法 可以正常布局。
//- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewAutomaticDimension;
}
但是考虑到没有高度缓存。所以想替换成您这个。
期待您的回复!~
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.