【发布时间】:2018-07-19 17:10:11
【问题描述】:
我目前正在制作一个天气应用程序,并希望在集合视图中填充当天的天气。数据设置在一个数组中,如下所示:
[["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])
但是得到错误'Cannot subscript a value of type '[[String]]' with a index of type 'IndexPath'
任何帮助将不胜感激:)
【问题讨论】:
-
indexPath.row而不是indexPath我猜(或indexPath.section,但这很少见)?但很明显,我不会使用String的数组。我会使用自定义结构/类。这更有意义。
标签: arrays swift uicollectionview