纯代码TableCell/CollectionCell注意的问题

图片来源网络.jpg

iOS 11之后 heightForHeaderInSection的方法设置后不生效

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if (section == 1) {
        return 10;
    }
    return 0;
}

解决方案:

self.tableView.estimatedSectionHeaderHeight = 0;

heightForFooterInSection设置后不生效

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    if (section == 1) {
        return 10;
    }
    return 0;
}

解决方案:

self.tableView.estimatedSectionFooterHeight = 0;

TableCell使用纯代码写的布局,不自动适应布局的问题,需要在填充数据的时候调用
[self layoutIfNeeded];

- (void)fillViewWithAddress:(NSString *)address {
    [self layoutIfNeeded];
    if (!IS_VALID_STRING(address)) {
        self.labelAddress.text = @"选择收货地址";
    } else {
        self.labelAddress.text = address;
    }
}

TableCell纯代码布局,布局约束写在- (void)layoutSubviews

- (void)layoutSubviews {
    [super layoutSubviews];
    [self.labelAddress mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.trailing.equalTo(self);
        make.leading.equalTo(self).offset(10);
        make.bottom.equalTo(self).priorityLow();//将底部的约束priority设置成低优先级
        make.height.equalTo(@(44));
    }];
}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。