0

NSCollectionView を使用して水平方向のリストを表示します。このように、すべてのセルが最初のセル位置で重なります。

画像を投稿するのに十分な評判がありません。[cell1,cell2,cell3]、それらはすべて最初のセル位置で重なります。1 つのセルのように見えますが、実際には 3 つのセルがあります。

私のメインコード:

ViewController.h

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.flowLayout.scrollDirection = NSCollectionViewScrollDirectionHorizontal;
    self.collectionView.dataSource = self;
    self.collectionView.delegate = self;
    self.collectionView.selectable = YES;
    self.collectionView.allowsMultipleSelection = YES;
    [self.collectionView registerNib:[[NSNib alloc] initWithNibNamed:@"ScreenShotCellView" bundle:nil] forItemWithIdentifier:NSStringFromClass([ScreenShotCellView class])];
}

#pragma mark - NSCollectionViewDataSource
- (NSInteger)numberOfSectionsInCollectionView:(NSCollectionView *)collectionView {
    [self.collectionView.collectionViewLayout invalidateLayout];
    return 1;
}

- (NSInteger)collectionView:(NSCollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    return self.screenshotItems.count;
}

- (NSCollectionViewItem *)collectionView:(NSCollectionView *)collectionView itemForRepresentedObjectAtIndexPath:(NSIndexPath *)indexPath {
    NSCollectionViewItem *itemCell = [self.collectionView makeItemWithIdentifier:NSStringFromClass([ScreenShotCellView class]) forIndexPath:indexPath];
    if ([itemCell isKindOfClass:[ScreenShotCellView class]]) {
        ScreenShotCellView *cellView = (ScreenShotCellView *)itemCell;
        ScreenshotItem *itemData = [self.screenshotItems objectAtIndex:indexPath.item];
        cellView.item = itemData;
    }
    return itemCell;
}

#pragma mark - NSCollectionViewDelegateFlowLayout
- (NSSize)collectionView:(NSCollectionView *)collectionView layout:(NSCollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
    return CGSizeMake(100, self.collectionView.frame.size.height - 20);
}

- (CGFloat)collectionView:(NSCollectionView *)collectionView layout:(NSCollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
    return 10;
}

- (CGFloat)collectionView:(NSCollectionView *)collectionView layout:(NSCollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
    return 10;
}

どうすれば修正できますか?

4

1 に答える 1