Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView extra space at bottom

My tableview has an extra space at the bottom, as you see in the picture:

All the rows in the tableView have a fixed height of 71pt.

enter image description here

like image 907
Guilherme Torres Castro Avatar asked Feb 21 '15 02:02

Guilherme Torres Castro


5 Answers

Ok, I got it.

The "Adjust Scroll View Insets" was marked on my viewController (not my tableView).

Here is an answer with a detailed explanation

like image 56
Guilherme Torres Castro Avatar answered Oct 23 '22 19:10

Guilherme Torres Castro


In my case tableView was created programmaticaly and I had to set tableView.estimatedRowHeight to make the space disappear

like image 44
iOS Unit Avatar answered Oct 23 '22 17:10

iOS Unit


@urgentx's answer did most of what I wanted but didn't get all the way there. I'm in a similar situation (upside down UITableView for a chat app) however their suggestion fully disables safe area behavior which isn't desirable on devices like the iPhone X because it means the tableview will be clipped by both the home indicator and any top navigation bars.

I did the following in order to make the tableview still correctly avoid safe areas while inverted:

override func viewDidLoad() {
    super.viewDidLoad()
    self.automaticallyAdjustsScrollViewInsets = false
    self.tableView.contentInsetAdjustmentBehavior = .never
}

and then:

override func viewWillLayoutSubviews() {
    super.viewWillLayoutSubviews()
    //fetch the safe area in layoutSubviews since this it's possible that they can change when the device is rotated
    let safeArea = self.tableView.safeAreaInsets
    //insets are **flipped** because the tableview is flipped over its Y-axis!
    self.tableView.contentInset = .init(top: safeArea.bottom, left: 0, bottom: safeArea.top, right: 0)
}

This in essence replicates contentInsetAdjustmentBehavior = .automatic behavior but with the insets flipped across the Y-axis.

like image 5
Allison Avatar answered Oct 23 '22 18:10

Allison


In my case this was due to having a footer of height 18 by default at the bottom of the UITableView. Setting it to 1 removed the extra space at the bottom.

like image 4
Integrating Stuff Avatar answered Oct 23 '22 17:10

Integrating Stuff


This is how it can be fixed easily through Storyboard (iOS 11):

Select Table View > Size Inspector > Content Insets: Never

like image 4
Saeed Ir Avatar answered Oct 23 '22 17:10

Saeed Ir