即使正在加載圖像,我也遇到圖像未顯示的問題。我已經嘗試了這幾種不同的方式和相同的結果...沒有圖像。我得到的白色矩形是故事板中指定的尺寸和顏色。我在popover中獲得正確數量的矩形。該日誌正確顯示名稱和ID。UICollectionView圖像不顯示
如果我直接調用數組,我會得到相同的結果......白色矩形。
我的目標是iOS7。運行Xcode 5.0.2。圖像來自SQL數據庫。這是一個實時應用程序,我正在更新到完整的iOS7,並且我正在交換UICollectionView的自定義網格佈局。使用一個CollectionViewController,嵌入到通過UIButton訪問的NavigationController中。正如你所看到的,沒有自定義的單元格。圖像將顯示在彈出窗口中,然後用戶可以選擇更改底層視圖的背景。
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"BckgndCell" forIndexPath:indexPath];
NSDictionary * tempDict = [_arrayOfBckgnds objectAtIndex:indexPath.row];
NSNumber *buttonTagNumber = (NSNumber *)[tempDict objectForKey:@"id"];
int buttonTag = [buttonTagNumber intValue];
NSString *tempImage = [tempDict objectForKey:@"fileName"];
NSLog(@"Filename: %@", tempImage);
NSLog(@"ButtonTagNumber: %@", buttonTagNumber);
UIImageView *image = [[UIImageView alloc]init];
image.image = [UIImage imageNamed:tempImage];
NSLog(@"Image.image: %@", image.image);
// needed for selecting the background in didSelectItemAtIndexPath
_bgtag = buttonTag;
return cell;
}
,其包括實際命名在cellForItemAtIndexPath方法BackgroundCell(杜)和BackgroundCell控制器創建一個小的方法來設置圖像的修復。
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
BackgroundCell *cell = (BackgroundCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"BckgndCell" forIndexPath:indexPath];
NSDictionary * tempDict = [_arrayOfBckgnds objectAtIndex:indexPath.row];
NSNumber *buttonTagNumber = (NSNumber *)[tempDict objectForKey:@"id"];
int buttonTag = [buttonTagNumber intValue];
NSString *tempImage = [tempDict objectForKey:@"fileName"];
[cell setImage:[UIImage imageNamed:tempImage]];
// needed for selecting the background in didSelectItemAtIndexPath
_bgtag = buttonTag;
return cell;
}
主要的單元代碼;
- (id)initWithFrame:(CGRect)frame
{
_backgroundImage = [[UIImageView alloc] initWithFrame:self.contentView.bounds];
[self.contentView addSubview:_backgroundImage];
if (self) {
// Initialization code
}
return self;
}
-(void)setImage:(UIImage *)image
{
_backgroundImage.image = image;
}
我現在顯示的圖像...爲其他工作長時間休息。主要的是,調用單元控制器和其他一些東西。上面添加了我的修復程序。 –