Home:ALL Converter>How To Get Rid Of Extra Space Above The UITableViewStyleGrouped Section?

How To Get Rid Of Extra Space Above The UITableViewStyleGrouped Section?

Ask Time:2018-03-06T00:25:23         Author:finneycanhelp

Json Formatter

We're want to do two changes to our search results.

  1. Change the Collection View Controller to a Table View Controller
  2. Have only the second section header show and have it scroll away inline. In other words, don't be sticky and don't stay at the top.

In regards to changing the Collection View Controller to a Table View Controller. This involves changing the section headers from a UICollectionReusableView subclass to something else. Normally, the change would be to using a UITableViewHeaderFooterView.

In regards to making the second section header scroll on up inline and out of sight and thus not be sticky, there's an issue to my solution.

To make it non-sticky, I changed the tableview to be UITableViewStyleGrouped. This causes a look for the second section that is different than what we have now. We would like it back to how it looks now.

Here's what we have in the App Store now: App Store Version

Here's what we have when trying the UITableViewStyleGrouped approach and other changes:

New Approach With UI Issues

Notice the extra gray above the "Other cars..." section header? I figure I can probably solve the rounded corners and insets via a subclass of the UITableViewHeaderFooterView. However, it's not clear how to handle the extra space above the section.

Code:

override func viewDidLoad() {
    super.viewDidLoad()

    self.tableView.estimatedRowHeight = 800
    self.tableView.rowHeight = UITableViewAutomaticDimension

    let nib = UINib(nibName: "SearchResultsOtherCarsHeader", bundle: nil)
    tableView.register(nib, forHeaderFooterViewReuseIdentifier: "SearchResultsOtherCarsHeader")
             :
}

override func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {

    if section != 1 {
        return 0
    }

    return 30
}

override func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {

    if section != 1 {
        return nil
    }

    let searchResultsOtherCarsHeaderView = self.tableView.dequeueReusableHeaderFooterView(withIdentifier: "SearchResultsOtherCarsHeader") as! SearchResultsOtherCars

    return searchResultsOtherCarsHeaderView
}

How to get rid of the extra gray space above the section header?

Author:finneycanhelp,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/49115023/how-to-get-rid-of-extra-space-above-the-uitableviewstylegrouped-section
yy