Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 是否阻止TableView backgroundView通过每个部分的最后一个单元格?_Ios_Swift_Uitableview_Background_Storyboard - Fatal编程技术网

Ios 是否阻止TableView backgroundView通过每个部分的最后一个单元格?

Ios 是否阻止TableView backgroundView通过每个部分的最后一个单元格?,ios,swift,uitableview,background,storyboard,Ios,Swift,Uitableview,Background,Storyboard,我在UIViewController中嵌套了一个UITableView中的UITableView,它有多个部分,每个部分都有一个自定义的部分头,是UIView的一个子类。UItableView在代码和情节提要中设置了所有正确的委托和数据源 在代码中,页脚显式设置为0 无论出于何种原因,背景(下面的红色部分)似乎从每个部分的UITableViewCells中溢出 我的UITableView当前看起来如下所示: 我在故事板中的tableview设置如下所示: 最后,这里是控制tableView的

我在
UIViewController
中嵌套了一个
UITableView
中的
UITableView
,它有多个部分,每个部分都有一个自定义的部分头,是UIView的一个子类。
UItableView
在代码和情节提要中设置了所有正确的委托和数据源

在代码中,页脚显式设置为0

无论出于何种原因,背景(下面的红色部分)似乎从每个部分的
UITableViewCell
s中溢出

我的UITableView当前看起来如下所示:

我在故事板中的tableview设置如下所示:

最后,这里是控制tableView的代码,作为UITableView子类的扩展编写:

extension TestViewController: UITableViewDelegate {
 func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    return 64
}

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

func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
    return 34
}
}

extension TestViewController: UITableViewDataSource {

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


    let view = TestHeaderView()
    view.setLabelWithValues(valueType: "Example", amount: 1)
    return view
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return 2
}

func numberOfSections(in tableView: UITableView) -> Int {
    return 3
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "TestCell", for: indexPath) as! TestTableViewCell
    cell.testLabel?.text = "example"
    cell.testLabel2?.text = "example"
    cell.testLabel3?.text = "example"
    return cell
}
}

如何防止背景通过单元格的每个部分?

解决了这个问题:

看起来我必须在情节提要大小检查器列中将页脚大小设置为0(然后默认为1),如下所示:


这将保留页脚的单个像素宽度,因此将背景颜色切换为单元格的任何颜色。

看起来空间是由于页脚部分造成的。尝试实现
tableView(uquo:heightforfooterInstitution:)
delegate方法来降低页脚的高度。@ntsh,Daniel Lyon好主意。只是尝试了一下,结果是一样的。更新问题以包含代码,而不是
返回0
,请尝试
返回0.001