未调用 cellForItemAtIndexPath 但 numberOfItemsInSection 调用 [英] cellForItemAtIndexPath not called but numberOfItemsInSection does
问题描述
这可能是重复的帖子,但我没有找到解决方案.
This could be a duplicate post but I haven't found the solution.
我将 UICollectionView
设置为:
UINib *nib = [UINib nibWithNibName:@"CollectionViewCell"
bundle:[NSBundle mainBundle]];
[_collectionView registerNib: nib forCellWithReuseIdentifier:@"bCell"];
(我尝试设置委托,没有委托等).
(I've tried to set a delegate, without delegate, etcetera).
然后,只有
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
被调用而
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
没有.
我检查了我返回的 numberOfItemsInSection,它总是 >0(正好是 17).
I've checked the numberOfItemsInSection I return, and it's always > 0 (it's exactly 17).
我检查过调用 [_collectionView reloadData];
也没有任何反应.
I've checked to call [_collectionView reloadData];
and nothing happens either.
我尝试了不同的方法,但无法成功.
I've tried different things but I can't make it work.
此外,我的 UICollectionView
应该在这里,但它不是:
Furthermore, my UICollectionView
should be here but it's not:
有人知道吗?谢谢.
推荐答案
好的,我认为这对未来的问题很有用...
Ok I think this could be useful for future problems with this...
这是因为 StoryBoard 的限制.我真的不明白为什么会发生这种情况,因为我刚刚固定了一个水平空间.我删除了水平空间作为该视图的约束,一切正常.
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.
这篇关于未调用 cellForItemAtIndexPath 但 numberOfItemsInSection 调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!