Objective c 获取所有UICollectionViewCell
我想访问Objective c 获取所有UICollectionViewCell,objective-c,uicollectionview,uicollectionviewcell,Objective C,Uicollectionview,Uicollectionviewcell,我想访问UICollectionView中的所有UICollectionViewCell 但在下面的代码中,日志仅输出null CollectionCell是UICollectionViewCell的子类,titleLabel是它的属性。 你知道如何访问所有CollectionCell吗 for (NSInteger j = 0; j < [collectionView numberOfSections]; j++) { for (NSInteger i = 0; i < [
UICollectionView
中的所有UICollectionViewCell
但在下面的代码中,日志仅输出null
CollectionCell
是UICollectionViewCell的子类,titleLabel
是它的属性。你知道如何访问所有CollectionCell吗
for (NSInteger j = 0; j < [collectionView numberOfSections]; j++) {
for (NSInteger i = 0; i < [collectionView numberOfItemsInSection:j]; i++) {
CollectionCell* cell = [collectionView cellForItemAtIndexPath:[NSIndexPath indexPathForItem:i inSection:j]];
NSLog(@"%@", cell.titleLabel.text);
}
}
for(NSInteger j=0;j<[collectionView numberOfSections];j++){
对于(NSInteger i=0;i<[collectionView numberOfItemsInSection:j];i++){
收集单元*单元= [collectionView cellForItemAtIndexPath:[NSIndexPath indexPathForItem:i第1节:j]];
NSLog(@“%@”,cell.titleLabel.text);
}
}
cellForItemAtIndexPath仅为可见单元格返回一个UICollectionViewCell 一种方法是调用数据源方法
collectionView:cellForItemAtIndexPath:
但请记住:单元格是重复使用的,因此您不会得到唯一的单元格尝试强制转换
CollectionCell*cell=(CollectionCell*)[collectionView cellForRowItemAtIndex:Path:ZzZ]代码>?为什么需要所有的单元格?