【问题标题】:How to adjust the UITableview Header height dynamically according to the content in ios 8如何根据ios 8中的内容动态调整UITableview Header高度
【发布时间】:2015-06-24 07:07:41
【问题描述】:

我在我的项目中使用带有自动布局的情节提要(XCode 6.3),使用尺寸类 Wcompact hRegular。我无法根据内容动态设置 UITableView Header 的高度。

【问题讨论】:

标签: ios objective-c ios8


【解决方案1】:

您可以在更改内容时重新加载带有此标题的部分

类似这样的:

- (void) shouldUpdateSections:(NSIndexSet *)sections
{
        [self.view.tableView reloadSections:sections withRowAnimation:UITableViewRowAnimationAutomatic];
}

当你需要更新你的标题时调用这个方法。

为了提高性能,您可以只为此标题创建单独的部分。

【讨论】:

    【解决方案2】:

    处理 UITableView 标头的高度与处理单元格的高度非常相似。当你想让它动态化时,你需要在tableView:heightForHeaderInSection: 方法中为标题调用layoutIfNeeded 并返回结果帧的高度。

    可以在StackOverflow question 中对此进行出色而深入的描述。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-05-21
      • 2012-07-29
      • 1970-01-01
      • 1970-01-01
      • 2019-05-07
      • 2018-12-21
      • 2015-08-27
      相关资源
      最近更新 更多