简体   繁体   English

具有自定义节和单元格的TableView

[英]TableView with custom sections and cell

I have this kind of tableView and I have problem in that I have visible separator at bottom of every section. 我有这种tableView,并且我有一个问题,就是我在每个部分的底部都有可见的分隔符。 How can I remove it? 如何删除? I need to use it at the middle of sections but not it the bottom. 我需要在各部分的中间使用它,而不是在底部使用它。

Also I need the same space between sections. 我也需要节之间相同的空间。 And I get it. 我明白了。 My code 我的密码

- (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];
}

replace this 取代这个

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if(section == 0)
       return 15;
    return 1.0;
}

with

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if(section == 0)
       return 0;
    return 15.0;
}

and remove this two methods 并删除这两种方法

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section

To handle separators in viewDidLoad viewDidLoad处理分隔符

[self.tableView setSeparatorColor:[UIColor clearColor]];

in cellForRowAtIndexPath: you can customize separator view according to your indexPath.row and indexPath.section values like 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM