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

如何移除这些单元格?


当前回答

Uitableview额外的分隔线隐藏额外的分隔线隐藏在swift 3.0

 self.tbltableView.tableFooterView = UIView(frame: .zero)

其他回答

如果您不希望在最后一个单元格之后有任何分隔符,那么您需要为页脚设置一个接近零但非零的高度。

在你的UITableViewDelegate中:

func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
    return .leastNormalMagnitude
}

在Swift中移除UITableView中空行的额外分隔行

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
    self.yourTableview.tableFooterView = UIView()
}

你可以在最后添加一个空的页脚,它会隐藏空的单元格,但它也会看起来很难看:

tableView.tableFooterView = UIView()

有一个更好的方法:在表格视图的末尾添加1点线作为页脚,空单元格也将不再显示。

let footerView = UIView()
footerView.frame = CGRect(x: 0, y: 0, width: tableView.frame.size.width, height: 1)
footerView.backgroundColor = tableView.separatorColor
tableView.tableFooterView = footerView

改进J. Costa的解决方案:你可以通过下面这行代码对表进行全局更改:

[[UITableView appearance] setTableFooterView:[[UIView alloc] initWithFrame:CGRectZero]];

在第一个可能的方法中(通常在AppDelegate中,在:application:didFinishLaunchingWithOptions: method)。

界面构建器(iOS 9+)

只需将一个UIView拖到表中。在故事板中,它将位于自定义单元格下方的顶部。您可能更喜欢将其命名为“footer”。

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

请注意,通过调整高度,您可以根据自己的喜好影响如何处理表的“底部反弹”。(高度通常为0)。


用程序来做:

斯威夫特

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