UITableView+FDTemplateLayoutCell的HeaderFooterView问题

最近写了一个评论页面用到了UITableView+FDTemplateLayoutCell框架,先说下这个框架对于自动计算行高非常好用,项目里用到了一个组HeaderFooterView页需要自动计算高度,刚好框架了就有一个方法返回组视图的高度,十分开心的使用了

- (CGFloat)fd_heightForHeaderFooterViewWithIdentifier:(NSString *)identifier configuration:(void (^)(id headerFooterView))configuration;

但是发现约束过后竟然算不出高度,后来翻看源码发现,作者的回调BLock没有返回,导致数据没有进行刷新,所以计算的高度也不对。需要在源码里加入一行,搞定又可以开心的使用了

if (configuration) {
        configuration(templateHeaderFooterView);
 }
- (CGFloat)fd_heightForHeaderFooterViewWithIdentifier:(NSString *)identifier configuration:(void (^)(id))configuration {
    UITableViewHeaderFooterView *templateHeaderFooterView = [self fd_templateHeaderFooterViewForReuseIdentifier:identifier];
    >>>>mark--- 这里加一行代码,把视图返回出去,就可以正常计算了
    if (configuration) {
        configuration(templateHeaderFooterView);
    }
    
    NSLayoutConstraint *widthFenceConstraint = [NSLayoutConstraint constraintWithItem:templateHeaderFooterView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:CGRectGetWidth(self.frame)];
    [templateHeaderFooterView addConstraint:widthFenceConstraint];
    CGFloat fittingHeight = [templateHeaderFooterView systemLayoutSizeFittingSize:UILayoutFittingCompressedSize].height;
    [templateHeaderFooterView removeConstraint:widthFenceConstraint];
    
    if (fittingHeight == 0) {
        fittingHeight = [templateHeaderFooterView sizeThatFits:CGSizeMake(CGRectGetWidth(self.frame), 0)].height;
    }
    
    return fittingHeight;
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Swift1> Swift和OC的区别1.1> Swift没有地址/指针的概念1.2> 泛型1.3> 类型严谨 对...
    cosWriter阅读 11,163评论 1 32
  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 12,273评论 4 61
  • 看到那些 被炸死的 炸伤的 被毒气弹毒死的 痛苦的儿童们的 宣传照片 确实让人悲伤 我分不出来他们 是政府军占领区...
    逝水流年_0ad2阅读 208评论 0 1
  • 不一定是谁的公主 但一定是自己的女王 嗯嗯~ 终于结束两天的加班。。 因为是自己喜欢的事情 所以忙里偷闲去完成 美...
    爱做早餐的小娜子阅读 4,708评论 9 16
  • 双色球089期 欧阳小文字谜 卅求五二余花开 两载风雨二心累 零湖二海有客来 惯听乙酉早岁愁 断蓝:一边七角 龙头...
    人生如梦_fe23阅读 557评论 0 0