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: