Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cellForItemAtIndexPath not called but numberOfItemsInSection does

This could be a duplicate post but I haven't found the solution.

I'm setting my UICollectionView as:

UINib *nib = [UINib nibWithNibName:@"CollectionViewCell"                            bundle:[NSBundle mainBundle]]; [_collectionView registerNib: nib forCellWithReuseIdentifier:@"bCell"]; 

(I've tried to set a delegate, without delegate, etcetera).

But then, only the

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section gets called while

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath doesn't.

I've checked the numberOfItemsInSection I return, and it's always > 0 (it's exactly 17).

I've checked to call [_collectionView reloadData]; and nothing happens either.

I've tried different things but I can't make it work.

Furthermore, my UICollectionView should be here but it's not:

enter image description here

Does anyone have a clue? Thank you.

like image 220
Rafael Ruiz Muñoz Avatar asked Jun 12 '15 14:06

Rafael Ruiz Muñoz


2 Answers

Ok I think this could be useful for future problems with this...

It was because of constraints on the StoryBoard. I don't really understand why that happens, because I just had fixed an horizontal space. I removed the horizontal space as constraint for that View and everything works fine.

Well, let's life flow.

like image 198
Rafael Ruiz Muñoz Avatar answered Sep 18 '22 22:09

Rafael Ruiz Muñoz


I also face same issue and finally got to know that i have passed wrong class object for collectionViewLayout , i change to UICollectionViewFlowLayout instead of UICollectionViewLayout while creating object for UICollectionView like below its stared calling all delegate method.

 collectionView = UICollectionView(frame: CGRectMake(5, 0, 400, 40) , collectionViewLayout: UICollectionViewFlowLayout()) 
like image 35
Narayana Avatar answered Sep 20 '22 22:09

Narayana