在UITableView中隐藏页脚视图

New*_*der 19 iphone footer uitableview ios5

我一直在努力隐藏footerview.我的问题是,当我单击按钮时,我在页脚中有一个按钮,下面将添加一个部分作为最后一部分,按钮也将转移到新创建的部分,现在我想隐藏表格上一部分中的页脚更新部分后.

footerView.hidden = YES
Run Code Online (Sandbox Code Playgroud)

我在按钮动作中使用了它,但它不起作用.

Sha*_* TK 42

有四种解决方案.他们是,

解决方案1:

tableView.sectionHeaderHeight = 0.0;
tableView.sectionFooterHeight = 0.0;

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

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger )section {
    return 1.0;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger )section {
    return [[UIView alloc] initWithFrame:CGRectZero];
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger )section {
    return [[UIView alloc] initWithFrame:CGRectZero];
}
Run Code Online (Sandbox Code Playgroud)

解决方案2:

您可以通过尺寸选项卡下的界面构建器设置页脚/标题高度.

解决方案3:

设置contentInset属性.

self.tableView.contentInset = UIEdgeInsetsMake(-20, 0, -20, 0);
Run Code Online (Sandbox Code Playgroud)

它用于使顶部和底部接触边缘.

解决方案4:

实现以下内容,根据您的条件设置值.0.0将不被接受.较低的值应为1.0.

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger )section {
    if(section == 0) {
       return 6;
    } else {
       return 1.0;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger )section {
    return 5.0;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger )section {
    return [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger )section {
    return [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
}
Run Code Online (Sandbox Code Playgroud)

  • @@ Ramshad您应该引用或归因于您复制的工作.另外,指定0.00001f会导致零高度.http://stackoverflow.com/questions/2817308/reducing-the-space-between-sections-of-the-uitableview (3认同)

sha*_*irv 16

这应该做到这一点

tableView.tableFooterView.hidden = YES;
Run Code Online (Sandbox Code Playgroud)

  • 页脚视图有两种:tableFooterView和sectionFooterView.因此混乱...... (7认同)

小智 8

这可以通过实现委托方法来实现

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
  return CGFLOAT_MIN;
}
Run Code Online (Sandbox Code Playgroud)


Kam*_*icz 5

参考@J.Hong 的回答,Swift4版本(iOS 11.3):

func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
    return .leastNonzeroMagnitude
}
Run Code Online (Sandbox Code Playgroud)

与@Tim Newton 的回答相比:

  • 没有必要打电话 titleForFooterInSection
  • 简化CGFloat.leastNormalMagnitude-> .leastNonzeroMagnitude(更 Swifty IMO)