UITableView extra space at bottom

后端 未结 11 587
被撕碎了的回忆
被撕碎了的回忆 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: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
    }
    

提交回复
热议问题