1

画像のサイズが正しく表示される CollectionViewController を実装しようとしています。しかし、「collectionViewLayout sizeForItemAtIndexPath」メソッドを実装すると、画像が表示されません。理由を知っている人はいますか?ここに私のCollectionViewControllerコードがあります:

#import "PhotosViewController1.h"

@interface PhotosViewController1 ()

@end

@implementation PhotosViewController1


- (void)viewDidLoad
{

    [super viewDidLoad];
    _carImages = [@[@"Wild-Love.jpg",
                  @"d919004663f99c934b20c1bd46fcad3e.jpg",

                  @"164_v-viergalerie.jpg"] mutableCopy];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


#pragma mark -
#pragma mark UICollectionViewDataSource

-(NSInteger)numberOfSectionsInCollectionView:
(UICollectionView *)collectionView
{
    return 1;
}

-(NSInteger)collectionView:(UICollectionView *)collectionView
    numberOfItemsInSection:(NSInteger)section
{
    return _carImages.count;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
                 cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    PhotosCell *myCell = [collectionView
                                    dequeueReusableCellWithReuseIdentifier:@"MyCell"
                                    forIndexPath:indexPath];

    UIImage *image;
    int row = [indexPath row];

    image = [UIImage imageNamed:_carImages[row]];

    myCell.imageView.image = image;

    return myCell;
}


#pragma mark -
#pragma mark UICollectionViewFlowLayoutDelegate

-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    UIImage *image;
    int row = [indexPath row];

    image = [UIImage imageNamed:_carImages[row]];

    return image.size;
}


@end
4

0 に答える 0