UICollectionView使用过程中的常见错误
2017-09-17 16:59
260 查看
UITableView和UICollectionView是在IOS开发过程中使用得比较多的数据展示控件。这两个控件各有千秋,有各自的最适应场合。UICollectionView在使用的时候比UITableView更严格,特别是侧重于UICollectionViewCell的重用,在创建诸多对象的时候,一定要使用重用机制,否则就会报相应 的错误,下面就对这些常见错误做一个总结:
1.reason:'the cell returned from -collectionView:cellForItemAtIndexPath: does not have a reuseIdentifier。 cells must be retrieved by calling-dequeueReusableCellWithReuseIdentifier:forIndexPath:'说明cell必须使用dequeueReusableCellWithReuseIdentifier:forIndexPath这个方法进行创建,也就意味着我们必须设置cell的重用标识
2.reason: 'could not dequeue a view of kind: UICollectionElementKindCell withidentifier *** - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'--没有注册cell,也就意味着系统[b]不知道按那种方式来进行cell的创建。我们可以使用storyboard注册,xib注册和class注册。[/b]
3. reason:'UICollectionView must be initialized with a non-nil layout parameter':必须指定'UICollectionView的布局对象,如果没有,则不能使用其进行布局.那么就意味着我们必须传入一个布局对象,也就意味着只能通过[[UICollectionView alloc] initWithFrame:<#(CGRect)#> collectionViewLayout:<#(nonnull
UICollectionViewLayout *)#>];来创建UICollectionView控件
4.创建好UICollectionView对象后,没有看到预期的效果。程序不运行创建cell的方法:这是因为我们创建了UICollectionViewLayout,它里面没有任何的布局属性,也就意味着系统会认为每一个cell的大小都是0,那么就不会创建cell.所以我们需要给其创建一个能够进行具体布局属性设置的UICollectionViewFlowLayout,并在其中设置好属性
5. reason:'invalid nib registered for identifier (***) - nib must contain exactly one top level object which must be a UICollectionReusableView instance':在xib文件中只能定义一个顶级视图,简单说就是只能定义一个cell.如果定义了多个就会报这个错误。
看懂了这几种错误,在使用UICollectionView就会顺利很多啦。
作者:wuhu0723
链接:http://www.jianshu.com/p/1a21311112a7
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
1.reason:'the cell returned from -collectionView:cellForItemAtIndexPath: does not have a reuseIdentifier。 cells must be retrieved by calling-dequeueReusableCellWithReuseIdentifier:forIndexPath:'说明cell必须使用dequeueReusableCellWithReuseIdentifier:forIndexPath这个方法进行创建,也就意味着我们必须设置cell的重用标识
2.reason: 'could not dequeue a view of kind: UICollectionElementKindCell withidentifier *** - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'--没有注册cell,也就意味着系统[b]不知道按那种方式来进行cell的创建。我们可以使用storyboard注册,xib注册和class注册。[/b]
3. reason:'UICollectionView must be initialized with a non-nil layout parameter':必须指定'UICollectionView的布局对象,如果没有,则不能使用其进行布局.那么就意味着我们必须传入一个布局对象,也就意味着只能通过[[UICollectionView alloc] initWithFrame:<#(CGRect)#> collectionViewLayout:<#(nonnull
UICollectionViewLayout *)#>];来创建UICollectionView控件
4.创建好UICollectionView对象后,没有看到预期的效果。程序不运行创建cell的方法:这是因为我们创建了UICollectionViewLayout,它里面没有任何的布局属性,也就意味着系统会认为每一个cell的大小都是0,那么就不会创建cell.所以我们需要给其创建一个能够进行具体布局属性设置的UICollectionViewFlowLayout,并在其中设置好属性
5. reason:'invalid nib registered for identifier (***) - nib must contain exactly one top level object which must be a UICollectionReusableView instance':在xib文件中只能定义一个顶级视图,简单说就是只能定义一个cell.如果定义了多个就会报这个错误。
看懂了这几种错误,在使用UICollectionView就会顺利很多啦。
作者:wuhu0723
链接:http://www.jianshu.com/p/1a21311112a7
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
相关文章推荐
- findViewById()使用常见错误
- VS下使用openGL过程中的常见错误集合
- yum使用过程中的常见错误
- 分布式框架dubbo使用过程中常见错误及解决
- FragmentTabHost使用过程中常见的一个错误
- Android开发常见错误(4):使用adb过程中产生的问题
- Android 使用百度地图SDK 定位和显示基础地图常见错误 locationclient.start()和mapview is null等等
- yum使用过程中的常见错误 .
- linux使用过程中的常见错误
- 使用Oracle数据库过程中常见错误
- Android开发常见错误(5):使用Monkey自动化压力测试过程中遇到的问题
- MATLAB 使用矩阵过程中常见错误
- Caffe安装&使用过程中的常见错误
- Oracle使用和开发过程中常见错误
- Keil使用过程中的常见错误
- Linux centos上部署MySQL及在使用过程中常见错误的处理
- yum使用过程中的常见错误
- yum使用过程中的常见错误
- yum使用过程中的常见错误
- findViewById()使用常见错误