如何摆脱UITableViewStyleGrouped部分之上的额外空间?

时间:2018-03-05 16:25:24

标签: ios uitableview

我们希望对搜索结果进行两项更改。

  1. 将集合视图控制器更改为表视图控制器
  2. 只显示第二部分标题,并将其滚动内联。换句话说,不要粘,不要留在顶端。
  3. 关于将Collection View Controller更改为Table View Controller。这涉及将节标题从UICollectionReusableView子类更改为其他类。通常,更改将是使用UITableViewHeaderFooterView。

    关于使第二部分标题向上滚动并且不在视线内而不是粘性,我的解决方案存在问题。

    为了使其不粘,我将tableview更改为UITableViewStyleGrouped。这导致查找与我们现在不同的第二部分。我们希望它回到现在的样子。

    以下是我们现在在App Store中的内容: App Store Version

    这是我们在尝试UITableViewStyleGrouped方法和其他更改时所拥有的:

    New Approach With UI Issues

    注意“其他车......”部分标题上方的额外灰色?我想我可以通过UITableViewHeaderFooterView的子类解决圆角和插入。但是,目前尚不清楚如何处理该部分上方的额外空间。

    代码:

    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
    }
    

    如何摆脱节标题上方的额外灰色空间?

1 个答案:

答案 0 :(得分:0)

解决方案:

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

此解决方案的灵感来自@maddy和iPhone UITableView : How to remove the spacing between sections in group style table?

的评论