当我向下滚动时,为什么我看到更多单元格而不是numberOfRowsInSection返回值?

问题描述 投票:0回答:1

行数是3.但滚动时我在tableView中看到更多单元格。我看到高度为94的细胞具有分离器颜色。但是,我想在表视图中只有3个单元格。为什么我看到的细胞多于3?任何人都可以解释一下吗?

谢谢

    tableStyle.separatorColor = UIColor.red
    tableStyle.allowsSelection = false
    tableStyle.isScrollEnabled = true

    // register UINib for LogoStyle1, FieldStyle1, ButtonStyle1
    tableStyle.register(UINib(nibName: "LogoStyle1", bundle: nil), forCellReuseIdentifier: "LogoStyle1")
    tableStyle.register(UINib(nibName: "FieldStyle1", bundle: nil), forCellReuseIdentifier: "FieldStyle1")
    tableStyle.register(UINib(nibName: "ButtonStyle1", bundle: nil), forCellReuseIdentifier: "ButtonStyle1")

    self.view .addSubview(tableStyle)
}

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

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    if indexPath.row == 0 {
        return 120
    }else if indexPath.row == 1 {
        return 272
    }else{
        return 94
    }
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    switch indexPath.row {
    case 0:
        let cell = tableView.dequeueReusableCell(withIdentifier: "LogoStyle1", for: indexPath) as! LogoStyle1
        cell.backgroundColor = UIColor.clear
        return cell
    case 1:
        let cell = tableView.dequeueReusableCell(withIdentifier: "FieldStyle1", for: indexPath) as! FieldStyle1
        cell.backgroundColor = UIColor.black
        cell.delegate = self
        return cell
    case 2:
        let cell = tableView.dequeueReusableCell(withIdentifier: "ButtonStyle1", for: indexPath) as! ButtonStyle1
        cell.backgroundColor = UIColor.clear
        cell.delegate = self
        return cell
    default:
        fatalError()

    }

    }

这是截图:enter image description here

ios swift uitableview
1个回答
1
投票

这些不是单元格,但是正在填充可用空间的tableFooterView会将其删除:

tableStyle.tableFooterView = UIView()
© www.soinside.com 2019 - 2024. All rights reserved.