一个view上面放两个不同的collectionview
一个view上面放两个collectionview 而且注册的不同 但是最后只有第一个collectionview 上的cell能显示出来, 第二个显示不出来 是什么情况?
-(void)setTitleCollectionView
{
UICollectionViewFlowLayout *flowLayout = [UICollectionViewFlowLayout new];
[flowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
flowLayout.itemSize = CGSizeMake(20.0f, 20.0f);
flowLayout.minimumLineSpacing = 10;
flowLayout.minimumInteritemSpacing = 20;
flowLayout.sectionInset = UIEdgeInsetsMake(12.5f, 9.5f, 12.5f, 9.5f);
self.collectImageArray = [[UICollectionView alloc] initWithFrame:CGRectMake(0, [GeneralMethods handlerView_Y_And_Height:cycleImage], self.view.width, 45.0f) collectionViewLayout:flowLayout];
self.collectImageArray.showsVerticalScrollIndicator = NO;
self.collectImageArray.showsHorizontalScrollIndicator = NO;
self.collectImageArray.delegate = self;
self.collectImageArray.dataSource = self;
self.collectImageArray.backgroundColor = [UIColor clearColor];
[_collectImageArray registerClass:[HTYKLM_TitleCell class] forCellWithReuseIdentifier:CollectionPublishTitleIdentifier];
[self.scrollView addSubview:self.collectImageArray];
}
-(void)setBottomTableCollectionView
{
UICollectionViewFlowLayout *flowLayout1 = [UICollectionViewFlowLayout new];
[flowLayout1 setScrollDirection:UICollectionViewScrollDirectionHorizontal];
flowLayout1.itemSize = CGSizeMake(self.view.width, 200);
flowLayout1.minimumLineSpacing = 0.1;
flowLayout1.minimumInteritemSpacing = 0.1;
flowLayout1.sectionInset = UIEdgeInsetsMake(0.1, 0.1, 0.1, 0.1);
////
self.collectTable = [[UICollectionView alloc] initWithFrame:CGRectMake(0, [GeneralMethods handlerView_Y_And_Height:self.collectImageArray], self.view.width, self.view.height + 118) collectionViewLayout:flowLayout1];
self.collectTable.pagingEnabled = YES;
self.collectTable.showsHorizontalScrollIndicator = NO;
self.collectTable.showsVerticalScrollIndicator = NO;
self.collectTable.delegate = self;
self.collectTable.dataSource = self;
self.collectTable.backgroundColor = [UIColor grayColor];
[_collectTable registerClass:[HTYKLM_TableViewCollectionViewCell class] forCellWithReuseIdentifier:@"TableViewCell"];
[self.scrollView addSubview:self.collectTable];
}
这是我两个collectionview的创建
(UICollectionViewCell )collectionView:(UICollectionView )collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
if ([collectionView isEqual:self.collectTable]) {
HTYKLM_TableViewCollectionViewCell *cell = (HTYKLM_TableViewCollectionViewCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"TableViewCell" forIndexPath:indexPath];
// cell.backgroundColor = [UIColor redColor];
// cell.backgroundColor = [UIColor blueColor];
return cell;
}
else
{
HTYKLM_TitleCell *cell = (HTYKLM_TitleCell *)[collectionView dequeueReusableCellWithReuseIdentifier:CollectionPublishTitleIdentifier forIndexPath:indexPath];
cell.backgroundColor = [UIColor redColor];
return cell;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
collectionview里面是scrollview,他有偏移,偏移出了collectionview 导致它的cell方法也不调用。只要加上self.automaticallyAdjustsScrollViewInsets = NO就OK。