iOS
Swift
TableViewController
EmptyCells
iOSDevelopment

How to remove extra empty cells in TableViewController, iOS - Swift

Master System Design with Codemia

Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.

Introduction

Extra empty rows at the bottom of a UITableView are a common UIKit annoyance. They appear because the table view keeps drawing separator lines and cell slots even when the data source has no more real rows to show.

The standard fix is simple: assign an empty footer view so the table stops displaying those unused cells. This is one of the easiest UIKit polish improvements you can make.

The most common solution is:

swift
1override func viewDidLoad() {
2    super.viewDidLoad()
3    tableView.tableFooterView = UIView(frame: .zero)
4}

That tells the table view there is nothing meaningful after the last real row, so the extra empty cells are no longer drawn.

This works in UITableViewController and in ordinary view controllers that own a table view.

Why This Works

Without a footer view, the table tries to fill remaining vertical space using its default empty rows and separators. By adding a footer view, even an empty one, you replace that default area with something intentional.

It is a small API detail, but it is the normal UIKit answer to this problem.

Full Example in UITableViewController

swift
1import UIKit
2
3class ItemsViewController: UITableViewController {
4    let items = ["One", "Two", "Three"]
5
6    override func viewDidLoad() {
7        super.viewDidLoad()
8        tableView.tableFooterView = UIView(frame: .zero)
9    }
10
11    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
12        return items.count
13    }
14
15    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
16        let cell = tableView.dequeueReusableCell(withIdentifier: "Cell")
17            ?? UITableViewCell(style: .default, reuseIdentifier: "Cell")
18        cell.textLabel?.text = items[indexPath.row]
19        return cell
20    }
21}

If you run this with only a few items, the table will stop showing the unwanted empty rows below them.

Do Not Solve It by Faking More Data

A wrong approach is to try to hide the problem by pretending the table has more rows or by styling empty cells manually. That creates more complexity than necessary.

The footer-view fix is cleaner because it addresses the rendering behavior directly instead of distorting the data source.

Know When Empty Space Is Actually Fine

Not every table view should fill the entire screen visually. Sometimes empty space below a short list is perfectly acceptable. The issue is usually not the blank area itself, but the default separators and empty-row appearance that make the UI look unfinished.

An empty footer removes that noise while preserving a clean layout.

This Is a Presentation Fix, Not a Data Fix

The footer-view approach does not change the number of rows in the table. It only changes how the unused area below your real data is rendered, which is exactly why it is such a clean solution.

Common Pitfalls

  • Forgetting that tableFooterView belongs to the table view, not the controller.
  • Trying to fix the issue by adding fake rows to the data source.
  • Confusing ordinary blank space with the actual problem of visible empty separators.
  • Reapplying the fix repeatedly when one viewDidLoad assignment is enough.
  • Looking for a storyboard-only trick when the programmatic footer assignment is the standard answer.

Summary

  • Extra empty cells usually come from the table view's default rendering behavior.
  • Set tableView.tableFooterView = UIView(frame: .zero) to remove them.
  • This is the normal UIKit solution in UITableViewController and other table setups.
  • Do not fake more rows just to hide the issue.
  • The goal is not removing blank space, but removing the unwanted empty-row appearance.

Course illustration
Course illustration

All Rights Reserved.