Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

viewForFooterInSection not making UITableView Footer stick to bottom?

Yes, I have read a lot of other posts on this issue, none of the solutions have worked for me yet!

Basically, when I use viewForFooterInSection and heightForFooterInSection, the resulting footer "floats"

enter image description here

viewDidLoad and FooterView code:

override func viewDidLoad() {
    super.viewDidLoad()
    setupNaviationBarStyles()
    setUpNavBarButtons()
    navigationItem.title = "Kindle"
    tableView.register(BookCell.self, forCellReuseIdentifier: "cellId")
    tableView.backgroundColor = UIColor.lightGray 
    fetchBooks()
}   

 override func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
    let view = UIView()
    view.backgroundColor = .red
    return view
}

 override func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
    return 50
}

The problem seems to be specific to the iPhone x? In the iPhone 7 simulator the above code works perfectly:

enter image description here

I have tried to create a custom view in viewDidLoad like a lot of other threads suggested but no such luck yet:

let view: UIView = UIView(frame: CGRect(x: 0, y: 0, width: 
tableView.frame.size.width, height: 40))
view.backgroundColor = .red
self.tableView.tableFooterView = view

I appreciate any help around this issue, seems like the solution is probably simple but I have been researching for a while and haven't found anything to be very effective when simulating using an iPhone x.

Cheers!

like image 964
Harry Avatar asked Mar 06 '23 10:03

Harry


1 Answers

It's Apple's bug, not yours. They completely failed to think through the implications of the iPhone X.

All you can really do is set the navigation controller's isToolbarHidden to false, even though you have no toolbar content. That will take up the space behind the home indicator and the table will look decent.

like image 70
matt Avatar answered Mar 15 '23 22:03

matt