UITabView中tableHeaderView和tableFooterView的坑

tableHeaderView 在使用frame布局完成后使用mansory 来相对布局操作界面时就会出现


The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
2018-12-29 16:52:18.563718+0800 TuiTui[22592:4888976] [LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. 
    Try this: 
        (1) look at each constraint and try to figure out which you don't expect; 
        (2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "<MASLayoutConstraint:0x281ff3120 UIButton:0x102f06ab0.left == UIView:0x102f068d0.left + 30>",
    "<MASLayoutConstraint:0x281ff33c0 UIButton:0x102f06ab0.right == UIView:0x102f068d0.right - 30>",
    "<NSLayoutConstraint:0x2818b70c0 UIView:0x102f068d0.width == 0>"
)

Will attempt to recover by breaking constraint 
<MASLayoutConstraint:0x281ff33c0 UIButton:0x102f06ab0.right == UIView:0x102f068d0.right - 30>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.
2018-12-29 16:52:19.391112+0800 TuiTui[22592:4888976] [NetworkInfo] Could not successfully update network info for descriptor <CTServiceDescriptor 0x283baca80, domain=1, instance=2> during initialization.

错误的

   self.tabV.tableHeaderView = self.headV;

    _submitBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_submitBtn setTitle:@"xxx" forState:UIControlStateNormal];
    [_submitBtn setTitle:@"xx" forState:UIControlStateSelected];
    [_footV addSubview:_submitBtn];
    WS_ViewRadius(_submitBtn,23.4);
    [_submitBtn makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.footV).offset(30);
        make.right.equalTo(self.footV).offset(-30);
        make.height.equalTo(47);
        make.centerY.equalTo(self.footV);
    }];

正确的

  self.tabV.tableHeaderView = self.headV;
    [self.headV setNeedsLayout];
    [self.headV layoutIfNeeded];
    _submitBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_submitBtn setTitle:@"xxx" forState:UIControlStateNormal];
    [_submitBtn setTitle:@"xx" forState:UIControlStateSelected];
    [_footV addSubview:_submitBtn];
    WS_ViewRadius(_submitBtn,23.4);
    [_submitBtn makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.footV).offset(30);
        make.right.equalTo(self.footV).offset(-30);
        make.height.equalTo(47);
        make.centerY.equalTo(self.footV);
    }];

如果还有一个tableFooterView 要添加
错误的如下:

        self.tabV.tableHeaderView = self.headV;
        [self.headV setNeedsLayout];
        [self.headV layoutIfNeeded];
        [self addTopView];//添加headV的子视图依赖headV的left或right
        
        self.tabV.tableFooterView = self.footV;
        [self.footV setNeedsLayout];
        [self.footV layoutIfNeeded];
        [self addFootView];//添加footV的子视图依赖footV的left或right

正确的


 self.tabV.tableHeaderView = self.headV;
 self.tabV.tableFooterView = self.footV;
 [self.tabV setNeedsLayout];
 [self.tabV layoutIfNeeded];
 [self addTopView];
 [self addFootView];

原因是:
1、tabV设置tableHeaderView是不会去重新刷新一下相对布局,需要手动强制刷新。
2、第二种刷新完tableHeaderView,再去刷新tableFooterView就会失效,需要手动强制刷新tableView.

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 一、简介 <<UITableView(或简单地说,表视图)的一个实例是用于显示和编辑分层列出的信息的一种手段 <<...
    无邪8阅读 13,687评论 3 3
  • 解决添加到ScrollView上的UITableView控件自动向下偏移64像素的问题 首先理解1:即使UITab...
    CoderZb阅读 10,730评论 1 8
  • Swift1> Swift和OC的区别1.1> Swift没有地址/指针的概念1.2> 泛型1.3> 类型严谨 对...
    cosWriter阅读 13,902评论 1 32
  • 一、初始化方法 1:TableView风格设置。 - (instancetype)initWithFrame:(C...
    iOS_SXH阅读 5,903评论 1 10
  • 前一段时间在陪伴1群里,看见静静发了一个视频,视频里静静悠扬的歌声此起彼伏高亢嘹亮,孩子随着妈妈的歌声在跳舞,看...
    妹哆哆阅读 1,513评论 0 2

友情链接更多精彩内容