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

如何移除这些单元格?


当前回答

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

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

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

其他回答

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

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

iOS 7+使用故事板

简单地拖一个UIView到你的UITableView作为页脚。设置页脚视图的高度为0。

我想扩展一下我的回答:

简单地添加高度为0的页脚就可以了。(在SDK 4.2, 4.4.1上测试)

- (void) addFooter
{
    UIView *v = [[UIView alloc] initWithFrame:CGRectZero];

    [self.myTableView setTableFooterView:v];
}

或者更简单——在你设置tableview的地方,添加这一行:

//change height value if extra space is needed at the bottom.
[_tableView setTableFooterView:[[UIView alloc] initWithFrame:CGRectMake(0,0,0,0)]];

或者更简单——简单地删除任何分隔符:

[_tableView setTableFooterView:[UIView new]];

再次感谢wkw:)

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

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

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

Swift适用于:

tableView.tableFooterView = UIView()