UICollectionView这个视图,就是不显示,请教啊。
ios开发吧
全部回复
仅看楼主
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
level 1
米布zz 楼主
补充下
//定义展示的UICollectionViewCell的个数
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return 5;
}
//定义展示的Section的个数
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
return 1;
}
这两个方法也写了。
2014年11月24日 09点11分 2
level 2
大哥,别把前缀写这么长,看见想杀人。
你自己仔细检查坚持,把项目发给我。 就这一截代码怎么看?
2014年11月24日 16点11分 3
level 2
明天代码发给我,我晚上回来帮你看看
2014年11月24日 16点11分 4
level 1
我也遇到了同样的问题,原因在于初始化的frame传过来是空的,
UICollectionViewFlowLayout *flowLayout= [[UICollectionViewFlowLayout alloc]init];
UICollectionView *collectionView = [[UICollectionView alloc] initWithFrame:frame collectionViewLayout:flowLayout];
解决办法:保证传过来的frame不为空
2015年05月05日 08点05分 6
level 3
你这个要注册一下,用MVC模式,要不然会重用,代码太乱,看不下去,
2015年05月06日 15点05分 7
level 2
一般不显示 是frame 的问题 自己看看
2015年05月17日 07点05分 8
level 9
注册
2015年05月17日 07点05分 9
level 1
你看看你自定义cell里面初始化方法对不对
2015年12月01日 07点12分 10
level 1
UICollectionView继承自UIScrollView类,要他滚动,就是UIScrollView滚动的方法,
cv.alwaysBounceVertical = YES;
cv.contentSize = CGSizeMake(x,y); x,y至少有一个比框架cv.frame.size的宽或高的值大,才能股东
2015年12月30日 09点12分 11
最后是滚动
2015年12月30日 09点12分
level 1
看了上面的回答笑了,应该是自定义的CollectionCell,添加控件的方法写在init里面了,可是Cell初始化不会走init方法,直接走的initFrame方法,写在initFrame就好了
2016年05月04日 08点05分 12
1