【发布时间】:2018-03-05 16:25:23
【问题描述】:
我们希望对搜索结果进行两项更改。
- 将集合视图控制器更改为表视图控制器
- 只显示第二部分标题并使其滚动滚动。换句话说,不要粘人,不要停留在顶部。
关于将 Collection View Controller 更改为 Table View Controller。这涉及将部分标题从 UICollectionReusableView 子类更改为其他内容。通常,更改将是使用 UITableViewHeaderFooterView。
关于使第二部分标题向上滚动且不可见,因此不粘,我的解决方案存在问题。
为了使它不粘,我将 tableview 更改为 UITableViewStyleGrouped。这会导致寻找与我们现在不同的第二部分。我们希望它恢复到现在的样子。
这是我们在尝试 UITableViewStyleGrouped 方法和其他更改时所做的:
注意到“其他汽车...”部分标题上方的多余灰色了吗?我想我可能可以通过 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
}
如何去掉节头上方多余的灰色空间?
【问题讨论】:
-
尝试根据需要设置部分页眉和/或页脚高度。
-
感谢您的快速回复,@maddy 我添加了到目前为止的代码。我现在正在试验这些值。减少 heightForHeaderInSection 没有帮助。
标签: ios uitableview