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

如何移除这些单元格?


当前回答

我想扩展一下我的回答:

简单地添加高度为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:)

其他回答

iOS 7+使用故事板

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

试试这个

self.tables.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 10.0f)];

我只是在ViewDidLoad函数中添加了这一行,问题就解决了。

tableView.tableFooterView = [[UIView alloc] init]; 

当tableView有tableFooterView时UIKit不会创建空单元格。我们可以做个小技巧分配一个零高度的UIView对象作为tableView的页脚。

tableView.tableFooterView = UIView()

这里有另一种不使用分组表样式的方法,一种您可能猜不到的方法。向表中添加页眉和页脚(也许一个或另一个就足够了,还没有选中)会导致分隔符从填充行/空白行中消失。

我无意中发现了这一点,因为我想在桌子的顶部和底部留出一点空间,以减少触碰按钮的风险,而不是手指肥大的表格单元格。下面是一个将空白视图作为页眉和页脚插入的方法。使用您喜欢的任何高度,您仍然可以消除额外的分隔线。

- (void) addHeaderAndFooter
{
    UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 10)];
    v.backgroundColor = [UIColor clearColor];
    [self.myTableView setTableHeaderView:v];
    [self.myTableView setTableFooterView:v];
    [v release];
}

In response to @Casebash, I went back to the code in my app ("AcmeLists" List Manager in iTunes store...) and short-circuited the addHeaderAndFooter method to verify. Without it, I have the extra row separators; with the code, I have what you see in this window snap: no table row separators picture. So I'm not sure why it wouldn't have worked for you. Moreover, it makes sense to me that having any custom footer on a table view would necessarily have to stop drawing row separators for blank rows below it. That would be hideous. For reference, I looked at tables where there were more rows than could be viewed on screen, and then for a table with two rows. In both cases, no extraneous separators.

也许您的自定义视图实际上并没有添加。要检查这一点,将背景颜色设置为clearColor以外的颜色,例如,[UIColor redColor]。如果您在表格底部没有看到一些红色条,则表示您的页脚没有设置。