消除 UITableView 下面多余的分隔符 [英] Eliminate extra separators below UITableView

查看:31
本文介绍了消除 UITableView 下面多余的分隔符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

When I set up a table view with 4 rows, there are still extra separators lines (or extra blank cells) below the filled rows.

如何删除这些单元格?

推荐答案

界面生成器(iOS 9+)

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

Interface builder (iOS 9+)

Just drag a UIView to the table. In storyboard, it will sit at the top below your custom cells. You may prefer to name it "footer".

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

Here it is shown in green for clarity, you'd probably want clear color.

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

Note that by adjusting the height, you can affect how the "bottom bounce" of the table is handled, as you prefer. (Height zero is usually fine).

以编程方式进行:

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

目标-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 历史上:

添加到表格视图控制器...

Historically in iOS:

Add to the table view controller...

- (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];
}

这篇关于消除 UITableView 下面多余的分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆