Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
666 views
in Technique[技术] by (71.8m points)

ios - 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...