ios - 消除 UITableView 下面多余的分隔符

标签 ios uitableview cocoa-touch

当我设置一个包含 4 行的 TableView 时,填充行下方仍有额外的分隔线(或额外的空白单元格)。

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

image for extra separator lines in UITableView

最佳答案

界面生成器(iOS 9+)

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

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

请注意,通过调整高度,您可以随心所欲地影响表格“底部反弹”的处理方式。 (高度为零通常没问题)。

enter image description here


以编程方式执行此操作:

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

添加到 TableView 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];
}

关于ios - 消除 UITableView 下面多余的分隔符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1369831/

相关文章:

ios - 侧边菜单警告 : attempt to push a View Controller from where its navigationController == nil in swift

ios - PFUser 关系 - 解析云

ios - 如何从 UITableView 将按钮添加到详细 View 的顶部栏

ios - MYSQL - 排序查询

iphone - if([labelView.layer containsPoint :touchPoint]) not working in Xcode

objective-c - 如何在 Xcode 7.2 中创建类别?

ios - 哪些 Action 由 iOS 上的加速度计管理?

ios - 如何将 IOS 照片库中的图像加载到 UIWebView?

objective-c - 调用viewDidLoad()中的方法。使用索引路径

cocoa-touch - 如何在 iOS 工具栏中显示标准的向上/向下控件