iOS UITableView设置tableHeaderView时发生约束错误 UIView-Encapsulated-Layout-Height UIView-Encapsulated-Layout-Width
在将UITableView的tableHeaderView设置为我自己创建的View的时候,
当我为这个自定义View添加约束之后启动调试,
然后符号断点UIViewAlertForUnsatisfiableConstraints命中了,
终端输出了如下的报错信息:
(
"<SnapKit.LayoutConstraint:0x1702a64e0@MAskDetailVC.swift#120 UIView:0x1017eb5e0.height == 211.666666666667>",
"<NSLayoutConstraint:0x170682760 'UIView-Encapsulated-Layout-Height' UIView:0x1017eb5e0.height == (active)>"
) Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x170682760 'UIView-Encapsulated-Layout-Height' UIView:0x1017eb5e0.height == 212 (active)>
这其实是CollectionView为你的自定义View自动添加了其他约束,
然而它添加的约束和你添加的约束的优先级是相同的。
所以解决问题的关键就是将你设置的约束的优先级降低;
解决方案参考:
一、如果你使用了UIKit提供的API来设置约束,可以参考如下OC代码:
NSArray * collectionConstraints_V = [NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[_collectionview]-0-|" options:0 metrics:nil views:viewsDic];
[self addConstraints:collectionConstraints_V]; NSArray * collectionConstraints_H = [NSLayoutConstraint constraintsWithVisualFormat:@"H:|-103-[_collectionview]" options:0 metrics:nil views:viewsDic];
[self addConstraints:collectionConstraints_H]; NSLayoutConstraint * constraint = [NSLayoutConstraint constraintsWithVisualFormat:@"H:[_collectionview]-0-|" options:0 metrics:nil views:viewsDic].firstObject;
constraint.priority = UILayoutPriorityDefaultLow; [self addConstraint:constraint];
二、如果你使用了SnapKit来设置约束,可以参考如下Swift代码:
askContainer.snp.makeConstraints { (m) in
m.top.equalTo(detailTV.snp.top)
m.leading.equalTo(detailTV.snp.leading)
m.width.equalTo(SCREEN_WIDTH)
let height = m.height.equalTo(height).constraint
height.layoutConstraints.first?.priority = UILayoutPriorityDefaultLow
}
参考资料:http://blog.csdn.net/hello_hwc/article/details/47129711
转载请注明出处:http://www.cnblogs.com/ficow/p/7250330.html
iOS UITableView设置tableHeaderView时发生约束错误 UIView-Encapsulated-Layout-Height UIView-Encapsulated-Layout-Width的更多相关文章
- windows live writer 尝试登陆时发生意外错误,导致无法发表博客解决方案
刚用windows live writer发表博客, 但是出现如下提示: 尝试登陆时发生意外错误: 网络连接错误--尝试连接到一下日志时出错: http://www.cnblogs.com//xxxx ...
- C# HttpRequest基础连接已经关闭: 接收时发生意外错误
在c#中使用HttpWebRequest时,频繁请求一个网址时,过段时间就会出现“基础连接已经关闭: 接收时发生意外错误”的错误提示. 将webRequest的属性设置成下面的,经测试可以解决. we ...
- ORA-39127: 调用 "WMSYS"."LT_EXPORT_PKG"."SCHEMA_INFO_EXP" 时发生意外错误
expdp 告警提示: Export: Release 11.2.0.4.0 - Production on 星期日 4月 28 12:14:51 2019....ORA-39127: 调用 &quo ...
- 解决SQL将varchar值转换为数据类型为int的列时发生语法错误
今天遇到一个这样的错误,具体的报错情况如下 解决的方案如下. 数据库MSSQL在比较大小时,出错提示:“将 varchar 值 '24.5' 转换为数据类型为 int 的列时发生语法错!”分析数据库设 ...
- 11i REP-3000: 启动 Oracle Toolkit 时发生内部错误.
+---------------------------------------------------------------------------+ 应用对象程序库: Version : 11. ...
- 项目转移时发生的错误<springboot+mybatis(xml逆向工程自动生成)>
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'app ...
- Tomcat 设置自启动时遇到的错误问题与解决方案
首先,今天在做tomcat开机自启动时,原本很简单的一个问题,但却浪费了很长时间: 首先系统环境采用的是Window10,设置Tomcat自启动过程当中需要注意的是:JDK的版本和Tomcat的位数必 ...
- 数据库中插入数据时发生ora-00984错误
操作Oracle数据库,插入数据时显示:ORA-00984列在此处不允许错误,如下图所示: 出现的原因是由于,在插入字符或字符串型字段时.如果插入的数据是纯数字,则不会有错误:如果出现字符,则会报OR ...
- 使用vs2015编译器编译libpqxx时发生的错误以及解决办法
d:\libpqxx-4.0\libpqxx-4.0\src\strconv.cxx(195): error C2440: “=”: 无法从“std::basic_istream<char,st ...
随机推荐
- hibernate的查询缓存和二级缓存的配合使用
我的上一篇博客Hibernate缓存体系之查询缓存(query cache),以及list和iterate方法的差别介绍了查询缓存的概念,以及list和iterate的差别.读者可能注意到:那篇博客測 ...
- Codeforces Round #422 (Div. 2) C. Hacker, pack your bags! 排序,贪心
C. Hacker, pack your bags! It's well known that the best way to distract from something is to do ...
- SSM整理笔记3——配置解析
github:https://github.com/lakeslove/SSM 项目的目录结构如下 首先,配置web.xml <?xml version="1.0" enco ...
- android studio Error:Unable to tunnel through proxy. Proxy returns "HTTP/1.1 400 Bad Request"
android studio运行会遇到Error:Unable to tunnel through proxy. Proxy returns "HTTP/1.1 400 Bad Reques ...
- Handler有何作用?怎样使用?
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/u012974916/article/details/24580405 一 Handler作用和概念 ...
- yarn笔记
常用命令: 创建项目:yarn init 安装依赖包:yarn == yarn install 添加依赖包:yarn add Yarn命令列表 命令 操作 参数 标签 yarn add 添加依赖包 包 ...
- 程序中引入库文件的头文件 编译时并不需要显示的用gcc去链接他的库文件 why?
拿一个苹果系统下的c文件为例: testArr.c #include <stdio.h> int main() { , , , , }; printf(]); } 当我们编译的时候 一般 ...
- IOS中UIAlertView(警告框)常用方法总结
一.初始化方法 - (instancetype)initWithTitle:(NSString *)title message:(NSString*)message delegate:(id /*&l ...
- MapReduce ChainMapper/ChainReducer
The ChainMapper class allows to use multiple Mapper classes within a single Map task. The ChainRedu ...
- 如何查看一个Application是32位的还是64位的?
使用process explorer查看,找到对应的进程. 注册表的路径是Computer\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\ 使用powershell查 ...