为UITableView节标题返回CGFloat.leastNormalMagnitude会导致崩溃

我做了一个iOS 8的应用程序,使用分组的UITableView作为它的一个页面。 其中有多个部分使用CGFloat.leastNormalMagnitude (或Swift 2及以下的CGFloat.min )作为部分页眉和页脚高度来删除“默认”空间。 一切都很顺利,直到应用程序运行在iOS 9和10,它崩溃的这个错误:

终止应用程序由于未捕获的exception“NSInternalInconsistencyException”,原因:“节标题高度不得为负 – 节0提供的高度是-0.00000'

不知何故, 1任何值(除了舍入的0 )都被视为负数 – 使用1作为返回值将使页眉/页脚空间再次出现。

有没有解决这个问题的方法?

提前致谢。

我已经尝试了tableView(_:heightForHeaderInSection:)几个值,并发现:

  • leastNormalMagnitudeleastNonzeroMagnitude将被视为减号(因此崩溃)。
  • 零将使TableView返回默认的高度作为页眉/页脚。
  • 零与一之间的任何东西都将被视为减号。
  • 一个将使TableView返回默认的高度。
  • 任何超过一个(例如1.1)都会将页眉/页脚设置为实际的高度。

我最终使用1.1来解决我的问题。

希望这会帮助那里的人!

我有同样的问题,如果我设置节标题高度:

 tableView.sectionHeaderHeight = UITableViewAutomaticDimension tableView.estimatedSectionHeaderHeight = CGFloat.leastNormalMagnitude 

但是,如果我将我的控制器设置为委托(UITableViewDelegate)为我的表视图和实现:

 func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { return CGFloat.leastNormalMagnitude } 

那么它的工作

也许CGFloat.leastNonzeroMagnitude是你需要的!

有了这样的configuration:

 tableView.estimatedSectionHeaderHeight = 50.0; tableView.sectionHeaderHeight = UITableViewAutomaticDimension; 

我设法估计部分HeaderHeight正常工作我的自定义标题,还没有标题的所有部分(和没有空白),经过多次尝试,并感谢edopelawi的解释。

我不得不使用这个方法(bannerObject =自定义标题视图,没有bannerObject =甚至没有空格):

 - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section { id bannerObject = [self bannerObjectForSection:section]; if(bannerObject) { return UITableViewAutomaticDimension; } else { return 0.01f; } } 

而不是这个,甚至没有正确使用UITableViewAutomaticDimension自定义标题:

 - (CGFloat)tableView:(UITableView *)tableView estimatedHeightForHeaderInSection:(NSInteger)section { id bannerObject = [self bannerObjectForSection:section]; if(bannerObject) { return 50.0; // UITableViewAutomaticDimension don't calculate the correct size of custom headers } else { return 1.1; } }