Jessica Jessica - 5 months ago 35
Objective-C Question

Remove separator line for only one cell

I'm trying to remove the separator for one

UITableViewCell
. I did the following:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell;
cell = [super tableView:tableView cellForRowAtIndexPath:indexPath];

if (indexPath.row == 1)
cell.separatorInset = UIEdgeInsetsZero;

return cell;
}


(It's
static cells
.) When I run the app. The separator line is still there. How can I remove the separator line for one
cell
?

Answer

On iOS 8 you need to use:

cell.layoutMargins = UIEdgeInsetsZero

If you want to be compatible with iOS 7 as well you should do following:

if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
    [cell setSeparatorInset:UIEdgeInsetsZero];
}

if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
    [cell setLayoutMargins:UIEdgeInsetsZero];
}

ADD: If previous didn't work - use this. (from answer below)

 cell.separatorInset = UIEdgeInsetsMake(0, 1000, 0, 0);