ios - 我应该在我的 tableview 中使用 4 xib 还是使用 4 个不同的 tableview
问题描述
我需要关于在 1 个表视图与 4 个 xib 或使用 4 个表视图之间进行选择的帮助。
目前,我有一个 UI,其中 1. 完整的 UI 需要可滚动 2. 有标题,每个标题后都有一个 uiview(这个 uiview 的内容不同,总共 4 种不同的视图)。
在这些 xib 文件之一中,我也实现了图表。
我应该使用单个tableview,然后根据条件添加4个xib文件还是只使用scrollview作为基础,然后继续添加tableview。?
决定实施哪一个的参数应该是什么?
解决方案
用户单tableview,根据条件添加xibs。这是最好的方法。
1.您可以添加多个部分。根据部分,您可以相应地插入不同的视图 1. 您可以在每个部分中添加多行。2. 如果要显示的数据数量最少。例如高达5
。indexpath
通过签入部分添加 xibs 。
//Example
if indexPath.section == 0 {
switch indexPath.row {
case 1:
//First custom tableview cell
case 2:
//Second custom tableview cell
case 3:
//Third custom tableview cell
}
}
编辑
关于动态单元格高度,viewDidload
添加
yourTableview.rowHeight = someValue
yourTableview.estimatedRowHeight = someValue
//高度
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
switch indexPath.section {
case 0:
return UITableView.automaticDimension
case 1:
return your desired height if you want
default:
return 0
}
}
```
推荐阅读
- algorithm - 非连续元素的最大总和(动态规划)
- javascript - html侧边栏居中的图像页脚
- elasticsearch - 在 Elastic Search 7 中,是否可以有一个 Context Suggester 来提升而不是过滤?
- c++ - 如何获取数字的前 3 位数字?
- python - Pandas 合并多行多列
- c++ - Qt Creator 不会在具有多个实例化的模板代码中的断点处停止
- javascript - Eleventy,LiquidJS,以及重新定义 Markdown 库
- spring-boot - 多对多关系中的json无限递归
- asp.net-core - 在 ASP.NET Core MVC 中将值从一个控制器传递到另一个控制器
- python - 使用 OpenCV 保存 TIFF 时文件大小大于预期