我想獲得UICollectionView中的所有項目。是否有可能在iOS中獲取UICollectionView中的所有項目?
我對下面的代碼進行了編碼,但它並不按我想要的方式工作。我的CollectionView中有6個項目,但只顯示其中4個項目。我應該如何修改我的母鹿?
for(NSIndexPath *indexPath in self.viewCollection.indexPathsForVisibleItems) {
// for(imgCount in self.viewCollection.numberOfSections) {
// NSIndexPath *indexPath = self.viewCollection.indexPathsForVisibleItems;
// Get selected cell
MYCell* cell = (MYCell*) [_viewCollection cellForItemAtIndexPath:indexPath];
if(cell.checked == YES) {
imgCount = imgCount + 1;
NSString *imgName = [directoryContent objectAtIndex:indexPath.item];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@", imgName]];
NSData *imgFile = [NSData dataWithContentsOfFile:filePath];
if(imgCount == 1) {
[IMGDATA_grid appendString:[imgFile base64EncodedStringWithOptions:NSDataBase64Encoding76CharacterLineLength]];
}
else {
[IMGDATA_grid appendString:@","];
mTempData = [imgFile base64EncodedStringWithOptions:NSDataBase64Encoding76CharacterLineLength];
[IMGDATA_grid appendString:mTempData];
}
}
}
您已擁有收藏視圖數據源中的所有數據。無需遍歷項目。 – rmaddy
您的收藏視圖可以製作足夠的單元格以填充整個屏幕。當用戶滾動時,集合視圖將消失在屏幕一端的項目並在屏幕的另一端重新使用它們,這就是爲什麼使用'collectionView.dequeueReusableCell(...)'創建單元格的原因。 – Palle
您的單元格只是您模型中數據的視圖。從模型中獲取數據,而不是從單元格中獲取數據。 – Paulw11