【问题标题】:Create a model for create section - Swift为创建部分创建模型 - Swift
【发布时间】:2019-10-02 10:54:42
【问题描述】:

我需要创建一个带有部分的UITableView,并且我的值如下所示:

let sectionTitles = ["section-1", "section-2", "section-3"]

let Items = [["id": 100, "name":"jim", "family": "rason"],["id": 200, "name":"jim22", "family": "rason22"], ["id": 300, "name":"jim33", "family": "rason33"]]

还有:

section-1 代表["id": 100, "name":"jim", "family": "rason"]

section-2 代表["id": 200, "name":"jim22", "family": "rason22"]

section-3 代表["id": 300, "name":"jim33", "family": "rason33"]

如何为它创建一个模型并填充这个模型?

有没有创建模型的在线网站?

【问题讨论】:

    标签: swift uitableview codable uitableviewsectionheader


    【解决方案1】:

    你需要

    struct Section {
       let title:String
       let content:[Content]
    }
    
    struct Content {
       let id:Int
       let name,family:String
    }
    

    然后创建数组

    let arr = [Section(title:"First",content:[Content(id:100,name:"na",family:"fam")])]
    

    【讨论】:

      【解决方案2】:

      您可以使用这样的类或结构创建模型

      struct Section {
          let title:String
          let content:SectionData
      }
      
      struct SectionData {
          let id:Int
          let name,family:String
      }
      

      创建数组

      var arr : [Section] = []
      

      在数组中追加数据

      arr.append(Section(title:”Section1”, content: Content(id: 1, name: "lokesh", family: "hdf")))
       arr.append(Section(title:"Section2”, content: Content(id: 1, name: "lokesh", family: "hdf")))
         arr.append(Section(title:"Section3”, content: Content(id: 1, name: "lokesh", family: "hdf")))
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-03-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多