gpt4 book ai didi

ios - 来自 json 的表格 View 部分

转载 作者:行者123 更新时间:2023-11-30 11:16:32 24 4
gpt4 key购买 nike

我正在尝试使用 JSON 服务器响应中的部分填充表格 View 中的日期...

这些部分将是日期..并且我想将具有相同日期的对象添加到同一部分...

我正在尝试这样做:

                print("heree:")
print(matches.data?.count)
for matchdate in matches.data!{
datesarray.append(matchdate.dateGregorian!)
}
datesarray = datesarray.reduce([], {
$0.contains($1) ? $0 : $0 + [$1]
})
print(datesarray.count)
for date in datesarray{
for match in matches.data!{
if date == match.dateGregorian{
homeimg = clubImg(id: match.home!)
awayimg = clubImg(id: match.away!)
matchesarray.append(Matches2(homeimg: homeimg,homenamear: match.homeClubNameAr,awayimg: awayimg,awaynamear: match.awayClubNameAr,matchtime: match.dateHijri))
}
self.objectArray.append(Sections(sectionDate: date, sectionMatches: matchesarray))
}
}
DispatchQueue.main.async {
self.tableview.reloadData()
}
print("heree2:")
print(self.objectArray.count)

但我得到了一个非常错误的结果!

json 返回一个包含 149 个对象的数组.. uniq 数组有 74 个.. 最后 tableview 数组有 11026 个对象!!!!!如何以及为什么?

我做错了什么以及如何解决这个问题?

最佳答案

你可以试试

for date in datesarray{
matchesarray.removeAll()
for match in matches.data!{
if date == match.dateGregorian{
homeimg = clubImg(id: match.home!)
awayimg = clubImg(id: match.away!)
matchesarray.append(Matches2(homeimg: homeimg,homenamear: match.homeClubNameAr,awayimg: awayimg,awaynamear: match.awayClubNameAr,matchtime: match.dateHijri))
}
}
self.objectArray.append(Sections(sectionDate: date, sectionMatches: matchesarray))
}

关于ios - 来自 json 的表格 View 部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51692700/

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