Ios 显示空节的表视图分隔符
我将Ios 显示空节的表视图分隔符,ios,uitableview,Ios,Uitableview,我将UITableView设置为UITableView样式分组样式。每当节有一个或多个项目时,它都会在节标题下显示一个单像素分隔符。但是,如果节没有项目,则节之间没有分隔符 如何使分隔符出现在所有部分中,即使是没有单元格的部分 请注意,第1节和第2节与第一个单元格之间有分隔符,而第3节与第4节之间没有分隔符。您可以尝试自定义节标题视图。使用此委托函数:-(UIView*)tableView:(UITableView*)tableView for HeaderInSection:(NSInteg
UITableView
设置为UITableView样式分组
样式。每当节有一个或多个项目时,它都会在节标题下显示一个单像素分隔符。但是,如果节没有项目,则节之间没有分隔符
如何使分隔符出现在所有部分中,即使是没有单元格的部分
请注意,第1节和第2节与第一个单元格之间有分隔符,而第3节与第4节之间没有分隔符。您可以尝试自定义节标题视图。使用此委托函数:-(UIView*)tableView:(UITableView*)tableView for HeaderInSection:(NSInteger)节 使用这两种方法在节之间添加分隔符
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 44.0;
}
- (UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 30)];
[headerView setBackgroundColor:[UIColor brownColor]];
UIImageView *img = [[UIImageView alloc]initWithFrame:CGRectMake(0, 43, 320, 1)];
img.backgroundColor = [UIColor whiteColor];
[headerView addSubview:img];
return headerView;
}
一种解决方案是为每个空节添加页脚:
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return [self tableView:tableView numberOfRowsInSection:section] == 0 ? 0.5 : 0.00000001;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
if ([self tableView:tableView numberOfRowsInSection:section] == 0) {
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.bounds.size.width, 0.5)];
view.backgroundColor = tableView.separatorColor;
return view;
} else {
return nil;
}
}
注:
- 这将在表视图中显示
- 它不会在heightForFooterInSection中返回0,而是返回