UICollectionView和UITableView常见错误总结
来源:互联网 发布:matlab编程题目汇总 编辑:程序博客网 时间:2024/06/03 19:27
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,也就意味着系统不知道按那种方式来进行cell的创建。我们可以使用storyboard注册,xib注册和class注册。
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.如果定义了多个就会报这个错误。
6.自动往下偏移64个像素:把动态返回单元格的高度的方法写上,把父视图的automaticallyAdjustsScrollViewInsets属性设置为NO,为什么呢?往父视图上添加的第一个视图是UIScrollView以及它子类的对象的时候,会自动往下偏移64个像素。
8.设置了CollectionView的行间距为0,可还是有一个间距
解决方法:在controller中添加如下方法
// 设置只有当间距小于该值时,cell会进行换行
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
return 0;
}
看懂了这几种错误,在使用UICollectionView就会顺利很多啦。
- UICollectionView和UITableView常见错误总结
- UITableView和UICollectionView 联动的错误
- iOS常见错误9-UITableView,UIScrollView,UICollectionView偏移20像素
- UITableView 和 UICollectionView
- UITableView和UICollectionView使用中出现的问题总结
- UIScrollView嵌套UITableView和UICollectionView
- iOS8自动调整UITableView和UICollectionView布局
- iOS8自动调整UITableView和UICollectionView布局
- UITableView和UICollectionView的cell重用问题
- UICollectionView详解和UITableView的区别
- UITableView和UICollectionView列表出现重叠问题
- iOS8自动调整UITableView和UICollectionView布局
- iOS UICollectionView 和 UITableView cell更新 详解
- UITableView和UICollectionView的局部刷新
- UITableView和UICollectionView的方法学习一
- UICollectionView详解和UITableView的区别
- UICollectionView使用过程中的常见错误
- ajax常见错误和使用总结
- JSP中四种传递参数的方法
- ajax根据ID查询数据库并返回Json格式数据返回js,使用append显示到页面。判断json值为[]或者[[]]的问题。
- tf.get_variable函数的使用
- collection、set、list、map的存储方式。
- 实际项目中用到的logback例子
- UICollectionView和UITableView常见错误总结
- 读书摘抄
- cursor: pointer移动端点击高亮
- 图片自动生成svg代码的一个好玩的网站
- struts 导致的路径问题
- 图像拼接基本步骤
- 分布式架构学习之:035--MyCat在MySQL主从复制基础上实现读写分离
- angular对象简单介绍
- Linux常用的配置文件