How to Remove Extra Separator Lines in a UITableView

When your UITableView does not have enough data to fill out the length of the screen, it will show empty cells with separators to fill out the screen. I have run into several situations where the extra separator lines are not wanted. If you have run into this yourself, then here is an easy trick to get rid of them that does not require any code.

A UITableView has two different modes. One for static content, where you manually add each cell in Xcode’s Interface Builder and the other where you build up the content dynamically in code. The extra empty cells with separators only occurs when you are using dynamic content.

Add a Plain UIView to the Footer of the UITableView

To get rid of the empty cells, all we have to do is add an empty UIView to the footer of the UITableView. The UITableview has two insertions points to add a header and a footer view above and below where your cell prototypes are.

First, grab a plain UIView from the object browser, and drag it to the the footer position below all of your cell prototypes.

It worked! The separator lines are gone.

Custom Colors May Require Additional Work

If your UITableView uses the default background color, then you do not have to do any additional work. However, if you are using a custom background color for your UITableView or you want your footer to match the colors of your cells, then change the background color of the footer view to match. You may also have to drag the size of the footer view to be large enough to cover the screen if you have no data in your UITableView.

I hope you found this solution useful. If you know of a simpler way to accomplish the same thing without adding custom code, then leave a comment below.

Conversation
  • Adeel Miraj says:

    It appears that setting an empty view in the Footer for section doesn’t work anymore. Now one has to set that tableFooterView to remove the extra lines. The solution in this blog post will work in the storyboards only. However, you can set the the tableFooter in viewDidLoad in case you are using Nibs or creating your tableView programatically.

    Objective-C:
    tableView.tableFooterView = [UIView new];
    Swift:
    tableView.tableFooterView = UIView()

  • Comments are closed.