UITableView extra space at bottom

后端 未结 11 572
被撕碎了的回忆
被撕碎了的回忆 2020-12-15 20:15

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.

相关标签:
11条回答
  • 2020-12-15 20:22

    My problem didn't solve by the answers. i had a UISearchbar as tableHeaderView which caused the white space ( i don't know why) . I removed the searchbar from tableview in storyboard and in viewWillLayoutSubviews added in table header then problem solved.

    override func viewWillLayoutSubviews() {
        super.viewWillLayoutSubviews()
        tableView.tableHeaderView = searchBar
    }
    
    0 讨论(0)
  • 2020-12-15 20:24

    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.

    0 讨论(0)
  • 2020-12-15 20:26

    I had the same issue, with latest Xcode (11.3) with latest iOS (13.3) iPhone. I tried many answers, but none worked.

    My tableView has top, bottom, leading, and trail constraints but somehow there is large space at bottom below the last cell. (tableView.contentSize.height was almost double of what is needed) Data for tableView is not dynamic at all.It happens both when the view controller that has it shows it and when tableView is hidden then shown again.

    I solved it by using scrollView's delegate method like below, so that when the user starts dragging, height is adjusted. For me, it works so great, hope for you, too!

    // this is the best place to adjust the contentSize.height of tableView.
    func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
        print("scrollViewWillBeginDragging():") // optional
        // replace allParkingGeos.count with your data for tableView
        tableView.contentSize.height = CGFloat(allParkingGeos.count) * cellHeight
    }
    
    0 讨论(0)
  • 2020-12-15 20:27

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

    0 讨论(0)
  • 2020-12-15 20:32

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

    Select Table View > Size Inspector > Content Insets: Never

    0 讨论(0)
  • 2020-12-15 20:38

    In case there is an embedded navigation controller, checking "shows toolbar" creates bottom spacing in the view controller. Just uncheck it.

    0 讨论(0)
提交回复
热议问题