今天遇到一个关于UICollectionView的问题。

在xib中拖入UICollectionView,设置delegate和dataSource,都配置好了,但是发现,

部分数据源方法不被调用。

#pragma mark UICollectionView delegate and datasource

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {

    return 1;

}

 

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {

    return 17;

}

 //以上两个方法是被正常调用的

//但是cellForItemAtIndexPath方法不被调用

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

    static NSString *identifier = @"WHHostCollectionCell";

    WHHostCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath]; 

    return cell;

}

 - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{

}

 

发现其他方法正常,只有cellForItemAtIndexPath不被调用。查找了好长时间,误打误撞,发现将代码中的

layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;注释掉就可以正常回调了。

至于原因,还不知为什么,按理该行代码不应该影响方法的回调,所以还未确定问题,持续查找原因。

posted on 2016-01-06 16:16  瓜甜甜  阅读(11955)  评论(1编辑  收藏  举报