我有两个集合视图和一个显示名称,另一个显示相应人员的年龄。这些数据以“[[”Name“,”Age“],[”Name“:”Daniel“,”Age“:”20“],[”Name“:”Jake“ ,“Age”:“20”]]。这个数据来自于CSV文件,所以第一个元素是一个头。在collectionView cellForItemAtIndexPath里面,我正在检查集合视图并且提供数据库像row [rowPath.row] [ “名称”]和小区2 [indexPath.row] [ “时代” 然而,indexPath.row总是返回零,所以我想起来了头 -indexPath.row总是返回零
如何解决这个问题?这是我的代码 -
func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 2
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 1
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
if collectionView == self.nameCollectionView {
let nameCell = collectionView.dequeueReusableCellWithReuseIdentifier("NameCell", forIndexPath: indexPath) as! NameCell
nameCell.data.text = self.data?[indexPath.row]["Name"]
println(indexPath.row)
return nameCell
}
else{
let ageCell = collectionView.dequeueReusableCellWithReuseIdentifier("AgeCell", forIndexPath: indexPath) as! AgeCell
ageCell.data.text = self.data?[indexPath.row]["Age"]
return ageCell
}
}
如果您正在设置项目1的编号,那么您是如何得到indexPath.row多于0的? –
尝试将numberOfitems返回到self.data.count –