【问题标题】:after removing the tableheader from a UITableView, there is a gap left从 UITableView 中删除表头后,还有一个间隙
【发布时间】:2016-01-19 22:50:48
【问题描述】:

我有一个带有过滤器按钮的UITableView。如果按下按钮,则可能会发生表为空的情况。为了通知用户,我在这种情况下添加了一个表头视图。如果有要显示的行,我将标题设置回 nil。

更新:我不是在谈论节标题,而是在谈论表格标题。

一切都按预期工作,但如果删除表头,我会在桌子上看到一个间隙,这是以前没有的。知道如何摆脱它吗?

这是代码:

if( _sections.count == 0 ) {
    UIView *tableHeader = [self getTableHeader]; // make a view
    self.tableView.tableHeaderView = tableHeader;
}
else {
    self.tableView.tableHeaderView = nil;
    [self.tableView reloadData]; // I added this as a test - no luck
}

这是过滤掉所有内容之前的样子:

这是“空”的情况:

这是,如果我再次删除过滤器:

【问题讨论】:

    标签: ios objective-c uitableview ios9.2


    【解决方案1】:

    您是否尝试在- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section 中的 section != 0 时将标题高度设置为 0.0f

    编辑:
    我认为您正在寻找的解决方案是将self.tableView.tableHeaderView = nil; 替换为:T 先生在Why is there extra padding at the top of my UITableView with style UITableViewStyleGrouped in iOS7 中找到的self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.tableView.bounds.size.width, 0.01f)];

    【讨论】:

    • 你的意思是,差距实际上是第一节?因为我没有更改section-header代码,所以我添加了一个表头...
    • 我不完全确定 - 但在添加节标题时,我通常会确保处理所有情况的高度。不过我可能会误解,这是表格视图的标题还是部分的标题?
    • 不是节头,是表头。
    • 我认为您正在寻找的解决方案是将self.tableView.tableHeaderView = nil;替换为:T先生在stackoverflow.com/questions/18880341/…中找到的self.tableView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, self.tableView.bounds.size.width, 0.01f)];
    • 请编辑您的答案以反映评论中的解决方案。上面的答案不正确,评论起到了作用。谢谢!
    猜你喜欢
    • 2014-01-07
    • 2019-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多