views:

388

answers:

3

I know I can change the UITableView property separatorStyle to UITableViewCellSeparatorStyleNone or UITableViewCellSeparatorStyleSingleLine to change all the cells in the TableView one way or the other.

I'm interested having some cells with a SingleLine Separator and some cells without. Is this possible?

+3  A: 

Your best bet is probably to set the table's separatorStyle to UITableViewCellSeparatorStyleNone and manually adding/drawing a line (perhaps in tableView:cellForRowAtIndexPath:) when you want it.

Mike McMaster
A: 

Hi Mike, I am working on a grouped table view and I have 4 section. However I don't want any separator line between cells. I have tried the steps suggested by you but it is not working. Can you give some another way.

kaykay
A: 

Following Mike's advice, here is what I did.

In tableView:cellForRowAtIndexPath:

...
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];

    // Drawing our own separatorLine here because I need to turn it off for the
    // last row. I can only do that on the tableView and on on specific cells.
    // The y position below has to be 1 less than the cell height to keep it from
    // disappearing when the tableView is scrolled.
    UIImageView *separatorLine = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, cell.frame.size.height - 1.0f, cell.frame.size.width, 1.0f)];
    separatorLine.image = [[UIImage imageNamed:@"grayDot"] stretchableImageWithLeftCapWidth:1 topCapHeight:0];
    separatorLine.tag = 4;

    [cell.contentView addSubview:separatorLine];

    [separatorLine release];
}

// Setup default cell setttings.
...
UIImageView *separatorLine = (UIImageView *)[cell viewWithTag:4];
separatorLine.hidden = NO;
...
// In the cell I want to hide the line, I just hide it.
seperatorLine.hidden = YES;
...

In viewDidLoad:

self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone; 
hanleyp