skip to Main Content
Remove Unused UitableViewCell Separators

Remove the UITableViewCell separator for empty cells

Post Series: UITableView best practises

Today I’m going to show you all a pretty basic and standard thing that you should always do in your projects. This became now standard, but still a lot of developers don’t know how to do, or just don’t care about it.

And this is removing those separators for empty cells.

remove unused uitableViewCell separators how to

As you can see by default you have those separators there, no matter you don’t have anything inside that cell.

If you use taller cells, it’s okay, like in this example, but if your cells’ height is 44pt or around that, you’ll see a lot of those separators. And that’s just look unprofessional.

How to remove UITableViewCell separator for empty cells?

There are several ways to fix this issue.

  1. Set the Separator type to None in Interface Builder.
    1. Select your UITableView, in the Attributes Inspector (Right sidepanel), select the Separator and from the dropdown menu change it to None.
    2. This way though, it will not show any separators.
  2. Just fix it programmatically:

This is all you have to do. Put it into viewDidLoad() method and you are good to go. You’ll notice that those empty UITableViewCell separators are gone.

 

And since you don’t want to do it everywhere in your code, you can just create a BaseTableView (subclassed from UITableView) and for example in its’ awakeFromNib() method, call this code. So you can use it everywhere without adding this line again.

I know for some/lot developers ┬áit wasn’t very useful, since they knew this trick already, but I hope I could help someone who just started learning iOS and couldn’t figure out how to get rid of those ugly lines.