zoukankan      html  css  js  c++  java
  • 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;注释掉就可以正常回调了。

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

  • 相关阅读:
    2017ICPC沈阳赛现场赛 L-Tree (dfs)
    2019西北工业大学程序设计创新实践基地春季选拔赛 D(卢卡斯定理)
    Codeforces Round #454 (Div. 1) CodeForces 906D Power Tower (欧拉降幂)
    模板
    洛谷
    模板
    洛谷
    洛谷
    模板
    模板
  • 原文地址:https://www.cnblogs.com/guatiantian/p/5106048.html
Copyright © 2011-2022 走看看