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?
To hide UITableViewCell separator completely, simply set it's colour to UIColor. clearColor(). This will make the cell separator not visible.
When wanting to hide the separator, use the new class and set myTableView. hideLastSeparator = YES . The way this works is by obstructing the last separator by adding a new view over it.
So, to remove a cell from a table view you first remove it from your data source, then you call deleteRows(at:) on your table view, providing it with an array of index paths that should be zapped. You can create index paths yourself, you just need a section and row number.
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.
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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With