简体   繁体   中英

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. 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

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

in cellForRowAtIndexPath: you can customize separator view according to your indexPath.row and indexPath.section values like

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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