gpt4 book ai didi

ios - 有没有办法一次显示一个 UI Cell 而多次显示另一个 UI Cell?

转载 作者:行者123 更新时间:2023-11-28 13:45:23 25 4
gpt4 key购买 nike

我有一个 UITableView,它代表一个带有动态 UI 单元格的问卷。我创建了 2 个单元格。第一个 UI Cell 需要始终位于顶部(如标题/页眉),第二个 UI Cell 需要是动态的(这意味着第二个 UI Cell 可以显示 10 或 20 个问题)。有什么办法可以做到这一点吗?

我已经为两个 UI Cells 创建了一个 UITableViewCell,并且链接了所有组件。现在我不知道在哪里指定 Cell 0 返回 1 次,Cell 1 返回 X 次。还有我如何始终将 Cell 0 保持在顶部?

这是反射(reflect)我的问题的打印屏幕: enter image description here

这是我的代码:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

switch indexPath.row {

// Static cell - Checks Left
case 0:
let cell = tableView.dequeueReusableCell(withIdentifier: "checksLeftCell", for: indexPath) as! ChecksLeftTableViewCell
return cell

// Dynamic cell - Questions
case 1:
let cell = tableView.dequeueReusableCell(withIdentifier: Constants.defectAndDamageCell, for: indexPath) as! DefectAndDamageCheckCell
cell.configCell()
cell.delegate = self
return cell
default:
return UITableViewCell()
}
}

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

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {

switch indexPath.row {
case 0: return 100
case 1: return 400
default:
return 170
}
}

我希望顶部有“卡住”单元格,第二个单元格是动态单元格。

感谢您阅读本文,我希望我能很好地解释我的想法。

最佳答案

这不是对设计进行良好思考的迹象。看起来您根本不需要 UITableView。您可以使用每个组件的基本 UIView 获得更好的结果,例如标题、问题详细信息、标签等。

您可以使用 UIStackView 帮助自己。

关于ios - 有没有办法一次显示一个 UI Cell 而多次显示另一个 UI Cell?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55457135/

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