Namik Mustafayev Namik Mustafayev - 1 month ago 13
iOS Question

UICollectionView cellForItemAtIndexPath method is not getting called

cellForItemAtIndexPath
is not called. Everything is normal I think
what is problem?

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

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

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

cell.titleText.text=@"test";

return cell;
}

Answer

In your viewDidLoad method you probably want to add:

self.collectionView.delegate = self;
self.collectionView.dataSource = self;
[self.collectionView reloadData];

easy as that.

Comments