UICollectionView数据源方法不调用问题

今天遇到一个关于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;注释掉就可以正常回调了。

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

转载于:https://www.cnblogs.com/guatiantian/p/5106048.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值