Hi I have a TableViewController
with two static cells, however when displayed, it shows the two static cells, and then all the other empty cells for the tablevi
Setting the tableFooterView
should remove extra cell like views.
@IBOutlet weak var tableView: UITableView! {
didSet {
tableView.tableFooterView = UIView(frame: .zero)
}
}
Swift 4 Elaborating on HorseT's answer, first control drag from your Table View in your storyboard, to your View Controller class and create an outlet called tableView.
@IBOutlet weak var tableView: UITableView!
Then, your viewDidLoad in your View Controller should look something like this:
override func viewDidLoad() {
super.viewDidLoad()
tableView.dataSource = self
tableView.delegate = self
tableView.tableFooterView = UIView()
}
Add Below Code in your "override func viewDidLoad()" Or "override func viewWillAppear(_ animated: Bool)" functions.
tblOutletName.tableFooterView = UIView()
Based on above answers in swift.
tableView.tableFooterView = UIView(frame: .zero)
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
if you want to remove rows for all UITableViews
in your app, just add an extension like this:
Swift 5.0
extension UITableView {
override open func didMoveToSuperview() {
super.didMoveToSuperview()
self.tableFooterView = UIView()
}