ios - 在单个单元格中显示页眉页脚和单元格?
解决方案
考虑到您的表格视图没有任何页眉和页脚。
- 创建 3 种类型的单元格,即答案单元格、问题单元格和解决方案单元格。
- 根据您的 UI 要求设计您的单元格。
- 为问题、答案和解决方案单元格创建数据源。
在 TableView 的 CellForRowAtIndexPath 的 Delegate 方法中实现如下代码。
enum CellType : String {
case answer
case solution
case question
}
func tableView(_ tableView: UITableView,
cellForItemAt indexPath: IndexPath) -> UITableViewCell {
let cellType = arrayDataSource[indexPath.item]
switch cellType {
case .answer:
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "answerCell",
for: indexPath) as! AnswerCell
return cell
case .solution:
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "solutionCell",
for: indexPath) as! SolutionCell
return cell
case .question:
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "questionCell",
for: indexPath) as! QuestionCell
return cell
}
}
根据单元格类型创建数据源。
在表格视图的委托方法中管理行的高度。使用 iOS 9 中引入的 UITableViewAutomaticDimension。
以下链接了解自动行高:
https://www.raywenderlich.com/8549-self-sizing-table-view-cells
推荐阅读
- php - PHP如何在整个类中使用传递给方法的变量?
- python - 在 Django 中声明模型值
- delphi - FMX 中的可变高度 TListView 项
- roku - 如何使用 roSGScreen 打开新视图?- 罗库
- amazon-s3 - 即使除了最后一部分之外,部分大小超过 5MB,也会出现 EntityTooSmall 错误
- audacity - 如何从列表的元素中提取所有汽车?
- laravel - Laravel 中的 CORS 使用 fetch 下载本地存储上的文件时
- javascript - 悬停时BG图像缩小,不要重置位置
- permissions - 当用户为谷歌工作表运行脚本时,我无法更改编辑权限
- node.js - 如何从猫鼬模式中的数组中删除对象?