您的位置:首页 > 产品设计 > UI/UE

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

2015-07-27 16:28 435 查看
iOS 7中
UITableView
有时会crashes,而iOS 8却不会,错误如下:

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


出现这问题的一种原因是你在
tableHeaderView
tableFooterView
中使用了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;


注意
bottomHeaderView
frame
要手动设置,而且为了适配iPhone6,不要硬编码。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: