【发布时间】:2018-08-05 16:39:38
【问题描述】:
我正在尝试使用来自 JSON 服务器响应的部分填充 tableview 中的日期...
这些部分将是日期.. 我想将具有相同日期的对象添加到同一部分...
我正在尝试这样做:
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 个对象!!!!!!如何以及为什么?
做错了什么以及如何解决?
【问题讨论】:
-
你把这段代码放在哪里了?在 cellForRowAtIndexPath 方法中?
-
@Hoven no 在 viewdidload() 中调用的方法中