我有一個顯示圖像數組的UICollectionView
。單元格中的圖像顯示爲白色框而不是實際圖像。UICollectionView顯示空單元格
我複製並從另一種觀點認爲將這些代碼,並在其他視圖的偉大工程......但不知何故在這個其它查看其顯示像一個白盒的所有圖像。
所示包裝盒是等於應該顯示的圖像的數量。所以信息正確傳遞。
圖像像小白盒一樣顯示,但是當我點擊它們時,它們會將選中的圖像顯示到另一個UIImage
元素中,我放置在其他位置(請參閱image1,清除按鈕左側的綠色方塊會根據在哪個白細胞上觸摸)。
任何人都可以發現爲什麼在單元格中UIImage
無法正常顯示?
也許是值得metioning,我也有同樣觀點的人的tableview
// in viewDidLoad method
[self.myCollection registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"Cells"];
//
- (void)getAllIcons
{
NSArray* imgArrayRaw = [[NSBundle mainBundle] pathsForResourcesOfType:@"png" inDirectory:nil];
NSMutableArray* imgArray = [[NSMutableArray alloc] init];
for (NSString* imgArrayProccesing in imgArrayRaw) {
NSString* ho = [imgArrayProccesing lastPathComponent];
if([ho rangeOfString:@"btn-"].location != NSNotFound){
[imgArray addObject:ho];
}
}
_imgFiles = [ NSMutableArray arrayWithObjects:imgArray,nil];
_imgFiles = _imgFiles[0];
_myCollection.hidden = NO;
[_myCollection reloadData];
}
// Collection View
#pragma mark - UICollectionView Datasource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return [_imgFiles count];
}
- (NSInteger)numberOfSectionsInCollectionView: (UICollectionView *)collectionView
{
return 1;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cells" forIndexPath:indexPath];
UIImageView *imageView = (UIImageView *)[cell viewWithTag:101];
imageView.image = [UIImage imageNamed:[_imgFiles objectAtIndex:indexPath.row]];
cell.backgroundColor = [UIColor whiteColor];
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
[self changeIconImage:[_imgFiles objectAtIndex:indexPath.row]];
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
return CGSizeMake(50, 50);
}
- (UIEdgeInsets)collectionView:
(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
return UIEdgeInsetsMake(50, 20, 50, 20);
}
此搜索:
可能因爲你沒有設置數據源和委託?就像你使用TableView一樣,你必須設置它們。如果情況並非如此,那麼我現在不知道。 – 2013-05-11 17:45:48