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,不要硬编码。