美文网首页
UITabView中tableHeaderView和tableF

UITabView中tableHeaderView和tableF

作者: 夬大爷 | 来源:发表于2018-12-29 17:51 被阅读0次

    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.

    相关文章

      网友评论

          本文标题:UITabView中tableHeaderView和tableF

          本文链接:https://www.haomeiwen.com/subject/rvrplqtx.html