我当前正在制作天气应用,并且想用当天的天气填充集合视图。数据在这样的数组中设置:
[[“” 2018-07-19 18:07951670925:07951670925“,” cloudy2“,” 22“],[” 2018-07-19 21:00:00“,” cloudy2“,” 18“], [“ 2018-07-20 00:00:00”,“ cloudy2”,“ 15”],[“ 2018-07-20 03:00:00”,“ cloudy2”,“ 13”],[“ 2018- 07-20 06:00:00“,” cloudy2“,” 16“],[” 2018-07-20 09:00:00“,” cloudy2“,” 21“]]
对于我的收藏夹视图单元格,我有一个填充2个标签和一个图像视图的函数
cell.dispayContent(time: string, image: UIImage(named: string), temperature: string)
我需要一种遍历数组并将相关信息添加到单元格中的方法。我已经尝试过了:
cell.dispayContent(time: todayModel.todayArray[indexPath][0], image: UIImage(named: todayModel.todayArray[indexPath][1])!, temperature: todayModel.todayArray[indexPath][2])
但是出现错误“无法为类型为[[String]]的值下标”且索引类型为“ IndexPath”
任何帮助将不胜感激:)
答案 0 :(得分:1)
您应该使用indexPath.row
而不是IndexPath
,
let today = todayModel.todayArray[indexPath.row]
cell.dispayContent(time: today[0], image: UIImage(named: today[1])!, temperature: today[2])