gpt4 book ai didi

ios - 为什么我向下滚动时看到的单元格多于 numberOfRowInSection 的重新运行值?

转载 作者:行者123 更新时间:2023-11-28 14:59:08 25 4
gpt4 key购买 nike

行数是 3。但滚动时我在 tableView 中看到更多单元格。我看到带有分隔符颜色的高度为 94 的单元格。但是,我只希望表格 View 中有 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

最佳答案

这些不是单元格,而是填充可用空间的 tableFooterView,像这样摆脱它:

tableStyle.tableFooterView = UIView()

关于ios - 为什么我向下滚动时看到的单元格多于 numberOfRowInSection 的重新运行值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49089389/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com