【问题标题】:iOS swift tableView header with JSON array带有 JSON 数组的 iOS swift tableView 标头
【发布时间】:2016-10-27 12:17:09
【问题描述】:

我有一个UITableView这样的:

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

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)

                ...
           }

       }
   }

【问题讨论】:

标签: ios json swift uitableview uitableviewsectionheader


【解决方案1】:

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

检查此链接,如果有任何问题,请告诉我。我向您介绍了如何创建带有标题和选择的表格视图。

快乐编码

【讨论】:

  • 你在聊天中发送它
  • 你的代码中有很多错误,我在大约 82 个错误中做了什么
  • 我发送新版本,如果您检查此版本,我将不胜感激
  • @MohammadReza 兄弟你的问题解决了然后批准我的答案,这样我就可以向其他用户建议我的这个答案。谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-10-13
  • 1970-01-01
  • 2018-10-31
  • 2017-07-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多