Removing cell borders from a section of grouped-style UITableView

IphoneCocoa TouchUitableview

Iphone Problem Overview


I have a UITableViewController initialized with the grouped style and having multiple sections. For one of these sections, I'd like its constituent cells to be completely transparent and have no border. I plan to assign a custom view for every row in this section, but having that custom view surrounded by the grouped table cell looks bad :(

The following makes the background color of a cell black instead of transparent... And I still don't know how to get rid of the border.

cell.backgroundColor = [UIColor clearColor];

Any pointers? Thanks!

Iphone Solutions


Solution 1 - Iphone

NOTE: This doesn't appear to be working in iOS7 and above. For iOS7 try this answer.

For iOS6 and below, to remove the grouped background from a cell in a grouped table view cell:

This didn't work

cell.backgroundView = nil; // Did Not Work

This did

cell.backgroundView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];

If you have moved to ARC (I've heard this works, but haven't tested it)

cell.backgroundView = [UIView new];

Solution 2 - Iphone

You have to actually set

tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

to remove the border of cells.

Solution 3 - Iphone

The following hack works in iOS 7 – for now. :)

Subclass UITableViewCell, and use this cell for the section that shouldn't have separators.
Override the addSubview method in your cell subclass:

-(void)addSubview:(UIView *)view
{
    // The separator has a height of 0.5pt on a retina display and 1pt on non-retina.
    // Prevent subviews with this height from being added. 
    if (CGRectGetHeight(view.frame)*[UIScreen mainScreen].scale == 1)
    {
        return;
    }

    [super addSubview:view];
}

Solution 4 - Iphone

This is what worked for with having a Grouped style table

> [tableView setSeparatorColor:[UIColor clearColor]];

Solution 5 - Iphone

This code worked for me :)

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

Solution 6 - Iphone

Set the backgroundView of the cell to nil. For a grouped table, the cell image is part of that view.

Solution 7 - Iphone

Try using tableView.separatorColor = [UIColor clearColor];

And, don't use tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

I tested with both, if style is none, making the section borders invisible is not working, but instead just change its color, and section border will appear to be none.

iOS seems to be differentiating making an object none and making an object transparent

Solution 8 - Iphone

cell.backgroundColor = [UIColor clearColor];

cell.backgroundView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];

Solution 9 - Iphone

cell.backgroundView = [UIView new];

Works like a charm! Tested! iOS6

Solution 10 - Iphone

As of iOS 8, setting the separator attribute to none works as well.

Get rid of cell border

Solution 11 - Iphone

Setting a content view also gets rid of the border. Set your custom view to cell.contentView.

Solution 12 - Iphone

The easiest way to remove cell borders from a section of grouped-style UITableView:

[tableViewOutlet setBackgroundView:nil];

in the viewDidLoad method.

Solution 13 - Iphone

 UIView *backView = [[UIView alloc] initWithFrame:CGRectZero];
 backView.backgroundColor = [UIColor clearColor];
 cell.backgroundView = backView;
 cell.backgroundColor = [UIColor clearColor];
 [cell.contentView addSubview:imageView];

Solution 14 - Iphone

If you have a custom UITableCellView then you can add the following method to your view to remove the background view.

- (void)setBackgroundView:(UIView *)backgroundView
{
    // We don't want background views for this cell.
    [super setBackgroundView:nil];
}

Solution 15 - Iphone

I just thought I would convert my comment to @Intentss into an answer, because it maybe useful for those, using his solution.

Using iOS6.1 with a grouped UITabelView, using ARC:

> [tableView setSeparatorColor:[UIColor clearColor]];

Does not work

> cell.backgroundView = [[UIView alloc] initWithFrame:CGRectZero];

Does work

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTimView Question on Stackoverflow
Solution 1 - Iphoneuser160917View Answer on Stackoverflow
Solution 2 - IphoneChintan PatelView Answer on Stackoverflow
Solution 3 - IphoneAndreas LeyView Answer on Stackoverflow
Solution 4 - IphoneFede MikaView Answer on Stackoverflow
Solution 5 - IphoneNicolò CiraciView Answer on Stackoverflow
Solution 6 - Iphoneuser511132View Answer on Stackoverflow
Solution 7 - IphonepetershineView Answer on Stackoverflow
Solution 8 - IphoneSandip Patel - SMView Answer on Stackoverflow
Solution 9 - IphoneRicardo FunkView Answer on Stackoverflow
Solution 10 - IphoneprabhuView Answer on Stackoverflow
Solution 11 - IphoneBTRUEView Answer on Stackoverflow
Solution 12 - IphoneKevin ZychView Answer on Stackoverflow
Solution 13 - Iphoneuser1635181View Answer on Stackoverflow
Solution 14 - IphoneKostub DeshmukhView Answer on Stackoverflow
Solution 15 - IphoneCharles RobertsonView Answer on Stackoverflow