小编典典

消除 UITableView 下面多余的分隔符

javascript

当我设置一个有 4 行的表格视图时,在填充的行下方仍然有额外的分隔线(或额外的空白单元格)。

我将如何删除这些单元格?

UITableView 中额外分隔线的图像


阅读 247

收藏
2022-06-06

共1个答案

小编典典

界面生成器(iOS 9+)

只需将 UIView 拖到表格中即可。在情节提要中,它将位于自定义单元格下方的顶部。您可能更愿意将其命名为“页脚”。

为了清楚起见,这里以绿色显示,您可能想要清晰的颜色。

请注意,通过调整高度,您可以根据自己的喜好影响桌子的“底部反弹”的处理方式。(高度为零通常很好)。

在此处输入图像描述


以编程方式执行此操作:

Swift

override func viewDidLoad() {
    super.viewDidLoad()
    self.tableView.tableFooterView = UIView()
}

Objective-C

iOS 6.1+

- (void)viewDidLoad 
{
    [super viewDidLoad];

    // This will remove extra separators from tableview
    self.tableView.tableFooterView = [UIView new];
}

或者,如果您愿意,

    self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];

历史上在 iOS 中:

添加到表视图控制器…

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
     // This will create a "invisible" footer
     return CGFLOAT_MIN;
 }

如果有必要…

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{        
    return [UIView new];

    // If you are not using ARC:
    // return [[UIView new] autorelease];
}
2022-06-06