iOS-UI之UICollectionView must be initialized with a non-nil layout parameter'解决方式
2016-07-22 20:52
483 查看
出现错误:
解决方式:
用xib创建的集合视图
#import "ViewController.h"
#import "CollectionCell.h"
@interface ViewController () <UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
flowLayout.itemSize = CGSizeMake((self.view.bounds.size.width-10*2)/3, 300);
flowLayout.minimumInteritemSpacing = 10;
flowLayout.minimumLineSpacing = 20;
flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
UICollectionView *collView = [[UICollectionView alloc] initWithFrame:self.view.frame collectionViewLayout:flowLayout];
collView.delegate = self;
collView.dataSource = self;
[collView registerNib:[UINib nibWithNibName:@"CollectionCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"cell"];
[self.view addSubview:collView];
[collView reloadData];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return 60;
}
// The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
CollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
// cell.backgroundColor = [UIColor blueColor];
return cell;
}
<
aaf4
span style="font-size:18px;color:#666666;">- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
解决方式:
用xib创建的集合视图
#import "ViewController.h"
#import "CollectionCell.h"
@interface ViewController () <UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout>
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
flowLayout.itemSize = CGSizeMake((self.view.bounds.size.width-10*2)/3, 300);
flowLayout.minimumInteritemSpacing = 10;
flowLayout.minimumLineSpacing = 20;
flowLayout.scrollDirection = UICollectionViewScrollDirectionVertical;
UICollectionView *collView = [[UICollectionView alloc] initWithFrame:self.view.frame collectionViewLayout:flowLayout];
collView.delegate = self;
collView.dataSource = self;
[collView registerNib:[UINib nibWithNibName:@"CollectionCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"cell"];
[self.view addSubview:collView];
[collView reloadData];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
return 60;
}
// The cell that is returned must be retrieved from a call to -dequeueReusableCellWithReuseIdentifier:forIndexPath:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
CollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
// cell.backgroundColor = [UIColor blueColor];
return cell;
}
<
aaf4
span style="font-size:18px;color:#666666;">- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
相关文章推荐
- GUI - Web前端开发框架
- 评价ui设计作品好坏的八个标准(界面/交互设计研究)
- Jquery ui datepicker设置日期范围,如只能隔3天【实现代码】
- 为Yahoo! UI Extensions Grid增加内置的可编辑器
- Cocos2d-x UI开发之文本类使用实例
- winform异型不规则界面设计的实现方法
- 在ASP.NET 2.0中操作数据之二十:定制数据修改界面
- 谈谈对jquery ui tabs 的理解
- 在IE 浏览器中使用 jquery的fadeIn() 效果 英文字符字体加粗
- UI Events 用户界面事件
- 基于Bootstrap的UI扩展 StyleBootstrap
- jQuery UI结合Ajax创建可定制的Web界面
- jquery UI Datepicker时间控件的使用方法(基础版)
- ui组件之input多选下拉实现方法(带有搜索功能)
- Hallo.js基于jQuery UI所见即所得的Web编辑器
- 基于jQuery UI CSS Framework开发Widget的经验
- jquery ui 1.7 ui.tabs 动态添加与关闭(按钮关闭+双击关闭)
- jquery UI Datepicker时间控件的使用及问题解决
- jQuery UI设置固定日期选择特效代码分享
- Jquery ajax 同步阻塞引起的UI线程阻塞问题