对于这个问题使用Masonry是很好解决的。

注意:绿色的是label2,当indexpath.section % 2 == 0时,label2不存在。

关键代码如下:

if (indexPath.section % 2 == 0) {

[cell.label2 mas_updateConstraints:^(MASConstraintMaker *make) {

make.height.mas_equalTo(0);

}];

}

代码如下:

//
// ViewController.m
// XibTestDemo
//
// Created by 思 彭 on 2017/10/19.
// Copyright © 2017年 思 彭. All rights reserved.
// #import "ViewController.h"
#import "TableViewCell.h"
#import <Masonry.h> @interface ViewController ()<UITableViewDelegate, UITableViewDataSource> @property (nonatomic, strong) UITableView *tableView; @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self setUI];
} #pragma mark - 设置界面 - (void)setUI { self.tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
self.tableView.delegate = self;
self.tableView.dataSource = self;
self.tableView.backgroundColor = [UIColor clearColor];
self.tableView.tableFooterView = [[UIView alloc]init];
// 注册cell
[self.tableView registerNib:[UINib nibWithNibName: NSStringFromClass([TableViewCell class]) bundle:nil] forCellReuseIdentifier:@"TableViewCell"];
// 行高
// self.tableView.rowHeight = UITableViewAutomaticDimension;
// self.tableView.estimatedRowHeight = 100;
[self.view addSubview: self.tableView];
self.tableView.estimatedRowHeight = ;
self.tableView.estimatedSectionHeaderHeight = ;
self.tableView.estimatedSectionFooterHeight = ;
} #pragma mark - UITableViewDataSource - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return ;
} - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return ;
} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"TableViewCell" forIndexPath:indexPath];
if (indexPath.section % == ) {
[cell.label2 mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo();
}];
}
return cell;
} #pragma mark - UITableViewDelegate - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { return 0.001f;
} - (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return ;
} - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { if (indexPath.section % == ) {
return ;
}
return ;
} @end

 Demo地址: https://github.com/PengSiSi/XibDemo

iOS Xib布局某些控件显示或隐藏<约束的修改>的更多相关文章

  1. 利用来JS控制页面控件显示和隐藏有两种方法

    利用来JS控制页面控件显示和隐藏有两种方法,两种方法分别利用HTML的style中的两个属性,两种方法的不同之处在于控件隐藏后是否还在页面上占空位. 方法一:  1 2 document.getEle ...

  2. Android Visibility控件显示和隐藏

    Android控件显示和隐藏 visibility 可见(visible) XML文件:android:visibility="visible" Java代码:view.setVi ...

  3. Android控件显示和隐藏

    Android控件都有visibility属性,该属性有三个可能值:visible.invisible.gone.可以通过预设或是Java程序控制这些控件的显示或隐藏. 一.在XML配置文件设置 可见 ...

  4. ios开发之--系统控件显示中文

    虽然一直知道X-code肯定提供有语言本地化的设置地方,但是一直也做个记录,有些时候的汉化,还是需要使用代码去控制,键盘的右下角.navagiton的return使用代码修改,调用系统相机时,也是出现 ...

  5. 仿酷狗音乐播放器开发日志二十三 修复Option控件显示状态不全的bug(附源码)

    转载请说明原出处,谢谢~~ 整个仿酷狗工程的开发将近尾声,现在还差选项设置窗体的部分,显然在设置窗体里用的最多的就是OptionUI控件,我在写好大致的布局后去测试效果,发现Option控件的显示效果 ...

  6. Xamarin iOS教程之页面控件

    Xamarin iOS教程之页面控件 Xamarin iOS 页面控件 在iPhone手机的主界面中,经常会看到一排小白点,那就是页面控件,如图2.44所示.它是由小白点和滚动视图组成,可以用来控制翻 ...

  7. iOS学习之UIPickerView控件的关联选择

    接上篇iOS学习之UIPickerView控件的简单使用 接着上篇的代码 http://download.csdn.net/detail/totogo2010/4391870 ,我们要实现的效果如下: ...

  8. QT5:第二章 布局排版控件

    一.简介 在QT组件面板中有Layouts和Spacers两个组件面板 注意:布局排版控件不显示 1.Layouts(布局) Vertical Layout:垂直方向布局,组件自动在垂直方向上分布 H ...

  9. Java开发桌面程序学习(二)————fxml布局与控件学习

    JavaFx项目 新建完项目,我们的项目有三个文件 Main.java 程序入口类,载入界面并显示 Controller.java 事件处理,与fxml绑定 Sample.fxml 界面 sample ...

随机推荐

  1. 马的遍历(BFS

    https://www.luogu.org/problemnew/show/P1443 模板BFS...... #include<iostream> #include<cstdio& ...

  2. 优化编辑器的编程语言 mlton

    MLton 是整个程序的优化编译器的标准ML编程语言.

  3. Docker:18.x版本安装与卸载

    Docker CE 分为 stable, test, 和 nightly 三个更新频道.每六个月发布一个 stable 版本 初始化机器 #1.关闭警报 vi /etc/inputrc #然后将set ...

  4. const int* p

    若纠结于const int* p,int const* p,int* const p这三个指针,可以看视频 https://www.icourse163.org/learn/BUPT-10035640 ...

  5. [Hdoj] Fast Matrix Calculation

    题面:http://acm.hdu.edu.cn/showproblem.php?pid=4965 题解:https://www.zybuluo.com/wsndy-xx/note/1153981

  6. D3DFVF_XYZ和D3DFVF_XYZRHW的区别

    D3DFVF_XYZ和D3DFVF_XYZRHW的区别是:1.D3DXYZ默认的坐标系统用户区中心是 (0,0) 而rhw的左上角是 (0,0)2.D3DXYZ默认的非光照的,而RHW默认就是高洛夫的 ...

  7. 8月清北学堂培训 Day1

    今天是赵和旭老师的讲授~ 动态规划 动态规划的基本思想 利用最优化原理把多阶段过程转化为一系列单阶段问题,利用各阶段之间的关系,逐个求解. 更具体的,假设我们可以计算出小问题的最优解,那么我们凭借此可 ...

  8. python 安装 pyHook

    下载网站:https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyhook 查看python版本 C:\Users\k\Desktop\file_trans> ...

  9. 一句话题解&&总结

    CF79D Password: 差分.两点取反,本质是匹配!最短路+状压DP 取反是套路,匹配是发现可以把操作进行目的化和阶段化,从而第二次转化问题. 且匹配不会影响别的位置答案 sequence 计 ...

  10. jenkins的任务卡住

    今天做jenkins任务的时候,发现一个启动后,一直卡住,在那转圈圈,其实这个时候,任务已经执行完了. 经过分析,因为这个任务是启动一个web服务,直接在机器上执行时,直接占用一个终端. 解决办法,放 ...