3

UICollectionView画像の配列を表示する があります。セル内の画像は、実際の画像ではなく白いボックスとして表示されています。

このコードを別のビューからコピーして貼り付けたところ、他のビューではうまく機能しました...しかし、どういうわけか、この他のビューでは、すべての画像が白いボックスのように表示されます。

表示されるボックスは、表示される画像の数と同じです。したがって、情報は正しく渡されます。

画像は小さな白いボックスのように表示されていますが、それらをクリックすると、選択した画像が別のUIImage場所に配置された別の要素に表示されます (画像 1 を参照してください。クリア ボタンの左側にある緑色の四角形は、どの白いセルに触れるかによって変化します) )。

UIImageセル内の が正しく表示されない理由を誰でも見つけることができますか?

同じビューにテーブルビューもあることに言及する価値があるかもしれません

// 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);
}

画像1: 画像1 ここに画像の説明を入力 ここに画像の説明を入力

4

1 に答える 1

1

申し訳ありませんが、問題を完全に診断するのに十分な情報が提供されていません。あなたのコードから、次の可能性のいずれかが疑われます。

a) 指定された画像がプロジェクトで見つからないため、nil が返されました。

b) タグ 101 を持つ imageView が見つからなかったため、nil が返されました。

c) imageView が見つかりましたが、有効になっていないか、非表示になっています。

「cell.backgroundColor」行にブレークポイントを設定し、これらの戻り値をそれぞれチェックし、imageView のステータスをチェックして、それが有効で非表示になっていないことを確認します。

于 2013-05-25T15:14:48.190 に答える