noobsmcgoobs
noobsmcgoobs

Reputation: 2746

UICollectionView not showing & delegate/datasource methods not being called

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

connections inspector connecting collectionview to delegate, datasource and outlet

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

Answers (2)

Sujatha C
Sujatha C

Reputation: 1

static NSString *identifier = @"Yourcellname";
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];

Upvotes: 0

Vivek Gajbe
Vivek Gajbe

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

Related Questions