ios - 我可以强制 UITableView 隐藏空单元格之间的分隔符吗?

当使用具有足够多单元格的普通样式 UITableView 时,UITableView 无法在不滚动的情况下全部显示,在下方的空白处不会出现分隔符细胞。如果我只有几个单元格,则它们下方的空白区域包括分隔符。

有没有办法可以强制 UITableView 删除空白空间中的分隔符?如果不是,我将不得不加载一个自定义背景,并为每个单元格绘制一个分隔符,这将使得继承行为变得更加困难。

我发现了一个有点类似的问题 here ,但我不能在我的实现中使用分组的 UITableView

最佳答案

适用于 iOS 7.* 和 iOS 6.1

最简单的方法是设置tableFooterView属性:

- (void)viewDidLoad 
{
    [super viewDidLoad];

    // This will remove extra separators from tableview
    self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
}

对于以前的版本

您可以将其添加到您的 TableViewController(这将适用于任意数量的部分):

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
     // This will create a "invisible" footer
     return 0.01f;
 }

如果不够也添加以下代码:

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{        
    return [UIView new];

    // If you are not using ARC:
    // return [[UIView new] autorelease];
}

https://stackoverflow.com/questions/1633966/

相关文章:

ios - applicationWillEnterForeground 与 application

objective-c - 新的自动引用计数机制是如何工作的?

ios - 如何使用 UIVisualEffectView 模糊图像?

ios - @property 在 Objective-C 中保留、分配、复制、非原子性

objective-c - 如何测试对象在 Objective-C 中属于哪个类?

ios - 裁剪 UIImage

objective-c - registerForRemoteNotificationTypes :

objective-c - 在此 block 中强烈捕获 self 可能会导致保留循环

objective-c - 如何检查 NSString 是否以某个字符开头

objective-c - 自定义 dealloc 和 ARC (Objective-C)