【发布时间】:2017-07-27 18:24:36
【问题描述】:
在 XCode 中,我正在编写一个程序,其中将 2D 字符串数组中的数据加载到 140 行 x 5 列的表中。在这个示例中,如果我的数组是 {{a,b,c}{d,e,f}},我想要一个类似
的表格a b c
d e f
但我一直得到什么 a, d 作为我的表的前 2 个元素,就在第一行。我的代码是:
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> GridViewCell {
if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "gridCell", for: indexPath as IndexPath) as? GridViewCell{
var i = 0
while (i < 5){
cell.textLabel?.text = wholeArray[indexPath.row][i]
cell.backgroundColor = UIColor.gray
return cell
}
}
else {
DLog("ERROR")
return GridViewCell()
}
}
如果有 indexPath.column,我会尝试但没有。我怎样才能得到这个来做我需要的?这是一个字符串数组;我试过 flatten() 没用。
【问题讨论】:
标签: arrays swift multidimensional-array uicollectionview uicollectionviewcell