2012-11-14 35 views
0

我在ViewController中以编程方式实现了集合视图,并将其与故事板连接起来,但滚动不起作用,并且一半的单元格不显示,因为它们褪色到右侧:setScrollDirection:对于CollectionView不起作用

- (void)viewDidLoad { 
    [super viewDidLoad]; 

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

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

} 

你知道为什么吗?

回答

1

您需要删除在viewDidLoad中所述的registerClass线并设置重用标识符在数据源方法UICollectionViewDelegate如下 -

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

    .... 

    return cell; 
} 
相关问题