2

我有一个UITableView这样的:

在此处输入图像描述

以及使用和tableView从 JSON 中获取数据:AlamofireSwiftyJson

JSON数据:

{
"timeline": {
"Milan": {
  "place": [
    {
      "name": "Place 1",
      "kind": "historic",
    },
    {
      "name": "Place 2",
      "kind": "historic",
    },
    {
      "name": "Place 3",
      "kind": "historic",
    },
    {
      "name": "Place 4",
      "kind": "historic",
    }
  ]
},
"Paris": {
  "place": [
    {
      "name": "Place 1",
      "kind": "historic",
    },
    {
      "name": "Place 2",
      "kind": "historic",
    },
    {
      "name": "Place 3",
      "kind": "historic",
    }
  ]
 }
}
}

我的问题是我如何将城市地点分隔在一个从名为 Place 的类继承的数组中,并将数据放入 tableView 中,如上图所示。

struct Place {
    var name = ""
    var type = ""
}

我写了一些代码,Alamofire .success 但这还不够:

if let jsonData = response.result.value {
           let json = JSON(jsonData)
           if let items = json["timeline"].dictionary {

           for (key,subJson):(String, JSON) in items {
               self.cityName.append(key)

                ...
           }

       }
   }
4

1 回答 1

0

https://gist.github.com/himanshu-benzatine/75fa44dc0e3f2752973a79984b182d70

检查此链接,如果有任何问题,请告诉我。我给你关于如何创建带有标题和选择的表格视图的基本概念。

快乐编码

于 2016-10-29T04:28:00.020 回答