*** Assertion failure in -[UITableView layoutSublayersOfLayer:]

iOS 7中UITableView 有时会crashes,而iOS 8却不会,错误如下:

*** Assertion failure in -[UITableView layoutSublayersOfLayer:], /SourceCache/UIKit_Sim/UIKit-2935.137/UIView.m:8794

出现这问题的一种原因是你在tableHeaderViewtableFooterView 中使用了Auto Layout 布局,如下:

self.tableView.tableHeaderView = _headerView;

注意_headerView是直接使用Auto Layout 布局的xib中的一个UIView对象,这种情况下就会出现上面的crash,解决方法应用计算机界的一句老话:”Any problem in computer science can be solved by another layer of indirection.”。 在tableHeaderView上添加一层,不要直接把_headerView赋值给tableHeaderView,代码如下:

UIView * bottomHeaderView = [[UIView alloc]init];
_headerView.bounds = CGRectMake(0, 0, CGRectGetWidth(self.tableView.frame), 100);
bottomHeaderView.height = 110;
[bottomHeaderView addSubview:_headerView];
self.tableView.tableHeaderView = bottomHeaderView;

注意 bottomHeaderViewframe 要手动设置,而且为了适配iPhone6,不要硬编码。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值