2015-11-08 80 views
1

我試圖從網站獲取數據並添加到我的collectionview,但是當我調用[self.collectionView reloadData]時,它不起作用。重新加載數據後未調用UICollectionView數據源方法

所以我的代碼如下:

- (void)viewDidLoad { 
    [PYBSkuApi getSKUList:1 andHotId:@"17" success:^(NSArray *skuList) { 
     self.dataSource = [NSMutableArray arrayWithArray:skuList]; 
     [self.skuCollectionView reloadData]; 
    }failure:^(AFHTTPRequestOperation *operation, NSError *error) { 

    }]; 
} 


// Data source 

- (NSInteger) numberOfSectionsInCollectionView:(UICollectionView *)collectionView { 
    return [self.dataSource count]; 
} 

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

- (UICollectionViewCell *) collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { 
.... 
} 

問題是,當我重新加載集合視圖中,self.dataSource更新後,它進入

- (NSInteger) numberOfSectionsInCollectionView:(UICollectionView *)collectionView 

但從來沒有進入

- (UICollectionViewCell *) collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath 

我不知道爲什麼。

+0

是什麼'numberOfSectionsInCollectionView:'返回?是否調用了'numberOfItemsInSection'? – rmaddy

+0

它是否返回計數? – jithin

+0

要確保您已將集合視圖的「委託」和「數據源」連接起來。 –

回答

0

你曾經被稱爲setCollectionViewLayout或initWithFrame:方法collectionViewLayout:

UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init]; 
[flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical]; 
[_collectionView setCollectionViewLayout:flowLayout]; 

_collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:flowLayout]; 
相關問題