Reputation: 2746
I have my data source methods
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return 10;
}
-(UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
LPDiaryCollectionViewCell *cell = (LPDiaryCollectionViewCell*)[collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
cell.testLabel.text = @"test";
return cell;
}
The cell is registered
[self.collectionView registerClass:[LPDiaryCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
Datasource, delegate and outlet are connected
But when I run, datasource methods don't get called and view is plain white with no UICollectionView showing.
EDIT: added the uicollectionview programattically instead. It displays but still no cell.
Upvotes: 2
Views: 8226
Reputation: 1
static NSString *identifier = @"Yourcellname";
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
Upvotes: 0
Reputation: 411
You have to set cell identifier for collection view cell in storybord(Ex. I have declared identifier = "ReuseCell"
) and used same storyboard identifer in cellForItemAtIndexPath method.
static NSString *identifier = @"ReuseCell";
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
Upvotes: 4