cellForItemAtIndexPath没有调用

  前几天在使用 UICollectionView 时碰到 cellForItemAtIndexPath 这个数据源方法没有被调用。这是一个 collectionView 返回 cell(item)的数据源方法。

  一般情况,它没有被调用的原因有下:

  1. 没有设置 delegate。

  2. 控制器没有遵守 UICollectiondataSource 协议。

  3. numberOfItemsInSection 中返回值为 0。

  4. 这也是我碰到的情况:就是初始化 collectionView 时要传入一个 flowLayout ,然后在设置 flowLayout.itemSize的 数值不对(它不能为0),如果  flowLayout.itemSize = CGSizeMake(0, 0) 会使cellForItemAtIndexPath不被调用。验证时可以给 itemSize 先设一个随便的值如(30,30),这样就 cellForItemAtIndexPath 就得到了调用。

posted @ 2016-09-10 11:04  布尔-  阅读(2098)  评论(0编辑  收藏  举报