level 1
米布zz
楼主
//创建视图
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
[flowLayout setItemSize:CGSizeMake(100, 100)];
[flowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
UICollectionView *cv = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, 400, 400) collectionViewLayout:flowLayout];
[cv registerClass:[WorkPhotoCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
cv.dataSource = self;
cv.delegate = self;
cv.backgroundColor = [UIColor orangeColor];
[self.view addSubview:cv];
//显示cell的内容
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString* cid = @"cell";
WorkPhotoCollectionViewCell *cell =[collectionView dequeueReusableCellWithReuseIdentifier:cid forIndexPath:indexPath];
cell.backgroundColor = [UIColor blackColor];
cell.img.image = [UIImage imageNamed:@"icon-1"];
return cell;
}
UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout
三个接口已经填写。
但是运行后,没有报错,就是什么都不显示,求教了。。。。。该怎么办。
2014年11月24日 09点11分
1
UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc]init];
[flowLayout setItemSize:CGSizeMake(100, 100)];
[flowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
UICollectionView *cv = [[UICollectionView alloc]initWithFrame:CGRectMake(0, 0, 400, 400) collectionViewLayout:flowLayout];
[cv registerClass:[WorkPhotoCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
cv.dataSource = self;
cv.delegate = self;
cv.backgroundColor = [UIColor orangeColor];
[self.view addSubview:cv];
//显示cell的内容
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString* cid = @"cell";
WorkPhotoCollectionViewCell *cell =[collectionView dequeueReusableCellWithReuseIdentifier:cid forIndexPath:indexPath];
cell.backgroundColor = [UIColor blackColor];
cell.img.image = [UIImage imageNamed:@"icon-1"];
return cell;
}
UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout
三个接口已经填写。
但是运行后,没有报错,就是什么都不显示,求教了。。。。。该怎么办。