2012-11-14 40 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; 
} 
相關問題