0

我在 ViewController 中以编程方式实现了一个集合视图,并将它与 Storyboard 连接,但滚动不起作用,并且一半的单元格没有出现,因为它们向右淡化:

- (void)viewDidLoad {
    [super viewDidLoad];

    [self.collectionView registerClass:[FotoCell class]
            forCellWithReuseIdentifier:@"cell"];

    UICollectionViewFlowLayout *myLayout = [[[UICollectionViewFlowLayout alloc]init]autorelease];
    [myLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
    [self.collectionView setCollectionViewLayout:myLayout];

}

你知道为什么吗?

4

1 回答 1

1

您需要删除 viewDidLoad 中的 registerClass 行,并在 UICollectionViewDelegate 的 Datasource 方法中设置重用标识符,如下所示 -

- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:      (NSIndexPath *)indexPath
{
    FotoCell *cell = [cv dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];

  ....

    return cell;
}
于 2013-01-28T00:35:47.937 回答