【问题标题】:viewForHeaderInSection not getting called on reloadDataviewForHeaderInSection 没有在 reloadData 上被调用
【发布时间】:2018-09-27 08:03:24
【问题描述】:

viewForHeaderInSection 没有在 reloadData 上被调用。加载视图时如何第一次调用它。很奇怪。有什么帮助吗?我已经实现了以下委托方法。

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 0;
}

-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForHeaderInSection:(NSInteger)section
{
    return 1500.0f;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return  UITableViewAutomaticDimension;
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {}

【问题讨论】:

  • tableView outlet、delegate和datasource也正确连接。
  • 使用该代码编辑您的问题并对其进行格式化以及附加信息。它在 cmets 中不是真正可读的,并且在它是重要信息时可能会被遗漏。
  • 我已经编辑了问题,请检查。
  • 请显示此代码的更多上下文。
  • 对我来说工作正常,也许问题出在你代码的其他部分。

标签: ios objective-c uitableview uitableviewsectionheader


【解决方案1】:

您的heightForHeaderInSection 可能会返回0,因为UITableViewAutomaticDimension 不起作用。为了使UITableViewAutomaticDimension 工作,您必须设置所有相对于单元格容器视图的左侧、右侧、底部和顶部约束。

【讨论】:

  • 我无法返回 10。占用是根据约束计算的。所以我必须返回 UITableViewAutomaticDimension。
  • 好的,这种情况下你需要实现self.tableView.estimatedSectionHeaderHeightstackoverflow.com/a/29763200/1155354
  • 那为什么在第一次加载视图时它可以工作,而当我显式调用reloadData时它却不工作?
猜你喜欢
  • 2011-09-01
  • 2017-02-11
  • 2015-05-22
  • 1970-01-01
  • 1970-01-01
  • 2012-10-01
  • 1970-01-01
  • 2011-09-17
  • 1970-01-01
相关资源
最近更新 更多