在单个单元格中显示页眉页脚和单元格?
Show Header Footer and cell in single cell?
请建议我是否可以在带有单元格页眉、单元格页脚和单元格的单张卡片中执行此操作。
不要将它们视为页脚和页眉。只是单元格的顶部、中部和底部。然后你可以构建一个包含这三个部分的复杂视图。
您可以将其中的 3 个实现为不同的自定义视图,单元格将只是所有它们的容器。
考虑到您的 table 视图没有任何页眉和页脚。
- 创建 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
}
}
根据单元格类型创建数据源。
在 table 视图的委托方法中管理一行的高度。使用UITableViewAutomaticDimension在iOS 9.
中介绍
下面link了解自动行高:
https://www.raywenderlich.com/8549-self-sizing-table-view-cells
请建议我是否可以在带有单元格页眉、单元格页脚和单元格的单张卡片中执行此操作。
不要将它们视为页脚和页眉。只是单元格的顶部、中部和底部。然后你可以构建一个包含这三个部分的复杂视图。 您可以将其中的 3 个实现为不同的自定义视图,单元格将只是所有它们的容器。
考虑到您的 table 视图没有任何页眉和页脚。
- 创建 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
}
}
根据单元格类型创建数据源。
在 table 视图的委托方法中管理一行的高度。使用UITableViewAutomaticDimension在iOS 9.
中介绍
下面link了解自动行高:
https://www.raywenderlich.com/8549-self-sizing-table-view-cells