Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sql-server-2005/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 获取所有UICollectionViewCell_Objective C_Uicollectionview_Uicollectionviewcell - Fatal编程技术网

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]?为什么需要所有的单元格?