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

Select your UITableView, go to the attribute inspector and change the style to Grouped.

enter image description here


in your viewDidLoad() function add this line of code:

tableView.tableFooterView = UIView()

To add to this, the reason why setting tableFooterView to UIView() removes the rows is because you are setting an empty UIView() object to the property. As per the Apple documentation:

var tableFooterView: UIView?

Therefore setting an empty UIView() will display nothing below your data for this property.

You can bring the empty rows back by resetting tableFooterView to the default value, like so:

tableView.tableFooterView = nil