首页 > 解决方案 > 我应该在我的 tableview 中使用 4 xib 还是使用 4 个不同的 tableview

问题描述

我需要关于在 1 个表视图与 4 个 xib 或使用 4 个表视图之间进行选择的帮助。

目前,我有一个 UI,其中 1. 完整的 UI 需要可滚动 2. 有标题,每个标题后都有一个 uiview(这个 uiview 的内容不同,总共 4 种不同的视图)。

在这些 xib 文件之一中,我也实现了图表。

我应该使用单个tableview,然后根据条件添加4个xib文件还是只使用scrollview作为基础,然后继续添加tableview。?

决定实施哪一个的参数应该是什么?

标签: iosuiscrollviewtableviewswift4

解决方案


用户单tableview,根据条件添加xibs。这是最好的方法。

1.您可以添加多个部分。根据部分,您可以相应地插入不同的视图 1. 您可以在每个部分中添加多行。2. 如果要显示的数据数量最少。例如高达5indexpath通过签入部分添加 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
        }
    }
    ```

推荐阅读