当使用具有足够多单元格的普通样式 UITableView
时,UITableView
无法在不滚动的情况下全部显示,在下方的空白处不会出现分隔符细胞。如果我只有几个单元格,则它们下方的空白区域包括分隔符。
有没有办法可以强制 UITableView
删除空白空间中的分隔符?如果不是,我将不得不加载一个自定义背景,并为每个单元格绘制一个分隔符,这将使得继承行为变得更加困难。
我发现了一个有点类似的问题 here ,但我不能在我的实现中使用分组的 UITableView
。
最佳答案
最简单的方法是设置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 中属于哪个类?
objective-c - registerForRemoteNotificationTypes :
objective-c - 在此 block 中强烈捕获 self 可能会导致保留循环