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
When a UITableView has fewer rows than the screen can display, it fills the remaining space with empty separator lines, creating "ghost" cells below your content. This is the default behavior of UITableView with the .plain style. The standard fix is setting tableFooterView to an empty UIView, which tells the table view to stop drawing separators after the last real cell. This one-line fix works in both UITableViewController and standalone UITableView setups.
The One-Line Fix
tableView.tableFooterView = UIView() sets a zero-height footer view. The table view stops drawing separator lines after the last cell because the footer view has no content and no separator.
Using a Standalone UITableView
The fix is identical whether you use UITableViewController or a regular UIViewController with a UITableView outlet.
Setting in Interface Builder
The .grouped table view style does not show empty cells by default because each section has its own background. However, grouped style adds section headers and footers with gray backgrounds, which changes the visual appearance.
Hiding Separators Entirely
Setting separatorStyle = .none removes all separator lines, including between real cells. Use this only if you want a completely separator-free design. The tableFooterView approach only removes separators below the last real cell.
Custom Footer View
A custom footer view serves double duty: it removes empty cells and provides a visual indicator that the user has reached the end of the list.
SwiftUI Equivalent
SwiftUI's List does not show empty rows by default. Extra separators can be hidden with .listRowSeparator(.hidden) in iOS 15+.
Common Pitfalls
- Setting footer on the wrong table view: In
UITableViewController, usetableView.tableFooterView. If you have a customUIViewControllerwith an outlet, make sure the outlet is connected — setting the footer on a nil table view does nothing. - Grouped style changes appearance: Switching to
.groupedremoves empty cells but adds section header/footer spacing and a different background color. This may not be the visual effect you want. - Footer view height miscalculation: A
UIView()with no frame has zero height, which is correct. If you settableFooterViewto a view with an explicit height, that space appears below the last cell. - Using separatorStyle = .none globally: This removes separators between real cells too, not just empty ones. If you want separators between cells but not below them, use
tableFooterView = UIView()instead. - iOS version differences: In iOS 15+,
UITableViewwith.plainstyle has a slightly different default appearance. ThetableFooterView = UIView()fix still works, but test on your target iOS version.
Summary
- Set
tableView.tableFooterView = UIView()to remove extra empty cells — this is the standard one-line fix - Works with both
UITableViewControllerand standaloneUITableView - Alternatively, use
.groupedtable style, which never shows empty cells (but changes visual appearance) - Use
separatorStyle = .noneonly if you want to hide all separators, including between real cells - SwiftUI
Listdoes not show empty rows by default

