UITabView中tableHeaderView和tableFooterView的坑

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


The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in  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. 
(
    "",
    "",
    ""
)

Will attempt to recover by breaking constraint 


Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in  may also be helpful.
2018-12-29 16:52:19.391112+0800 TuiTui[22592:4888976] [NetworkInfo] Could not successfully update network info for descriptor  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.

你可能感兴趣的:(UITabView中tableHeaderView和tableFooterView的坑)