gpt4 book ai didi

带有 JSON 数组的 iOS swift tableView header

转载 作者:行者123 更新时间:2023-11-28 08:25:03 26 4
gpt4 key购买 nike

我有一个像这样的 UITableView:

enter image description here

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

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)

...
}

}
}

最佳答案

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

检查此链接,如果有任何问题,请告诉我。我将向您介绍如何创建带有标题和选择的表格 View 的基本概念。

快乐编码

关于带有 JSON 数组的 iOS swift tableView header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40284373/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com