UITabView中tableHeaderView和tableFooterView的坑

tableHeaderView 在使用frame布局完成后使用mansory 來相對布局操作界面時就會出現(xiàn)


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.

?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

  • 一、簡介 <<UITableView(或簡單地說,表視圖)的一個實例是用于顯示和編輯分層列出的信息的一種手段 <<...
    無邪8閱讀 10,958評論 3 3
  • 解決添加到ScrollView上的UITableView控件自動向下偏移64像素的問題 首先理解1:即使UITab...
    CoderZb閱讀 5,465評論 1 8
  • Swift1> Swift和OC的區(qū)別1.1> Swift沒有地址/指針的概念1.2> 泛型1.3> 類型嚴謹 對...
    cosWriter閱讀 11,621評論 1 32
  • 一、初始化方法 1:TableView風格設置。 - (instancetype)initWithFrame:(C...
    iOS_SXH閱讀 1,974評論 1 10
  • 前一段時間在陪伴1群里,看見靜靜發(fā)了一個視頻,視頻里靜靜悠揚的歌聲此起彼伏高亢嘹亮,孩子隨著媽媽的歌聲在跳舞,看...
    妹哆哆閱讀 216評論 0 2

友情鏈接更多精彩內(nèi)容