[英]TableView with custom sections and cell
我有这种tableView,并且我有一个问题,就是我在每个部分的底部都有可见的分隔符。 如何删除? 我需要在各部分的中间使用它,而不是在底部使用它。
我也需要节之间相同的空间。 我明白了。 我的密码
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
if(section == 0)
return 15;
return 1.0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 14.0;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
return [[UIView alloc] initWithFrame:CGRectZero];
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
return [[UIView alloc] initWithFrame:CGRectZero];
}
取代这个
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
if(section == 0)
return 15;
return 1.0;
}
与
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
if(section == 0)
return 0;
return 15.0;
}
并删除这两种方法
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
在viewDidLoad
处理分隔符
[self.tableView setSeparatorColor:[UIColor clearColor]];
在cellForRowAtIndexPath:
您可以根据自己的indexPath.row和indexPath.section值自定义分隔符视图,例如
if(indexPath.row != self.yourArray.count-1)
{
UIImageView *line = [[UIImageView alloc] initWithFrame:CGRectMake(0, yourCellHeight -2, 320, 2)];
line.backgroundColor = [UIColor redColor];
[cell addSubview:line];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.