D4r*_*iNS 3 xcode nsindexpath ios uicollectionview
我有一个UICollectionView的项目数组(有2列和3行),我想用indexPath访问它但我不能使用它
如果我使用indexPath.row或indexPath.item我得到0,1,0,1,0,1.
如果我使用indexPath.section我得到0,0,1,1,2,2
我想要的是0,1,2,3,4,5,6
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
MenuCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
//cell.backgroundColor = [UIColor redColor ];
cell.backgroundColor = [UIColor whiteColor ];
UIImage* imagenprobar =[UIImage imageNamed: [imagenes objectAtIndex: indexPath.item]];
[cell.imagen setImage: imagenprobar];
cell.label.text = [textos objectAtIndex: indexPath.item];
return cell;
Run Code Online (Sandbox Code Playgroud)
}
使用(indexpath.section*yourTotalColumn)+indexPath.row计算阵列的确切索引进行UICollectionView.
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
......................
.......................
//Now calculate index of array (datasource) Note : here column is 2.
NSInteger index = (indexpath.section*2)+indexPath.row
cell.label.text = [textos objectAtIndex:index];
return cell;
Run Code Online (Sandbox Code Playgroud)
}
| 归档时间: |
|
| 查看次数: |
4441 次 |
| 最近记录: |