2013-03-24 81 views
1

我在「/ Documents/saved /」目錄下有幾個圖像爲png格式。 我裝這個目錄到所謂的「內容」 當我使用的NSLog查看此數組的內容,我看到的圖像,以及一個.DS_STORE文件數組 我想要做的是加載所有這些圖像插入UICollectionView細胞。將文檔子目錄中的圖像加載到UICollectionViewCell中

我想這一點,

[[cell collectionImageView] setImage: 
     [UIImage imageWithContentsOfFile: 
       [contents objectAtIndex:indexPath.item]]]; 

的collectionImageView連接到的UIImageView在UICollectionViewCell

但它似乎並不work.EDIT

NSString *dataPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/DImage"]; 
NSArray *contents = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:dataPath error:NULL]; 

的NSLog(@」 %@「,內容);

這給了我輸出

2013-03-25 10:37:20.186 aUX[543:c07] (
".DS_Store", 
"savedImage_0.png", 
"savedImage_1.png", 
"savedImage_2.png", 
"savedImage_3.png", 
"savedImage_4.png", 
"savedImage_5.png" 
) 

(我已經拖了一個名爲collectionImageView的UIImageView) 我需要顯示這些圖像逐一集合視圖細胞。

+1

多一點的代碼會有幫助。 「內容」數組中有什麼? – gaige 2013-03-24 20:05:36

+0

*什麼*不起作用? – Mundi 2013-03-24 20:37:08

回答

0

目前尚不清楚您使用的數據類型。也許打破你的一攬子計劃可能有助於使情況更加清晰。另外,用這種方法你可以用NSLog或者在調試器中檢查每一步。可能你的contents數組包含NSURL而不是NSStrings。用這種方法你可以找到答案。

+0

當我登錄的NSString *路徑,我得到 Path是.DS_Store 路徑savedImage_0.png 路徑savedImage_1.png 路徑savedImage_2.png 路徑savedImage_3.png 路徑savedImage_4.png 路徑savedImage_5。 png 我剛剛變黑屏。也許這是因爲開始時的.DS_STORE文件? – 2013-03-25 06:06:39

+0

不,你有一個文件名的數組。你需要完整的路徑。在我的答案中看到變化。 – Mundi 2013-03-25 06:22:09

+0

這個工程!非常感謝 !但是第一個單元格是空白的(因爲它正在顯示.DS_STORE文件)。有什麼建議麼 ? – 2013-03-25 09:31:34

-1
in ur cellForRowAtIndexPath 
cell.collectionImage.image=[contents objectAtIndex:indexPath.row]; 
return cell;