我一直在处理嵌套收集意见时遇到问题。 层次结构如下所示:
- outerCollectionView
- 的UIImageView
- 标签
- innerCollectionView
- 标签
- 的UIImageView
OuterCollectionView的细胞是在屏幕的大小(就像通过网页击)我已经设置outerCollectionView的委托和数据源是的UIViewController和innerCollectionView的委托和数据源是包含电池,如下所示:
在ViewController.m
-(FeaturedPageCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { FeaturedPageCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"FeaturedCell" forIndexPath:indexPath]; cell.nestedCollectionView.dataSource = cell; cell.nestedCollectionView.delegate = cell; [cell.nestedCollectionView setBackgroundColor:[[UIColor whiteColor] colorWithAlphaComponent:.01]]; cell.venueThumbnail.image = [UIImage imageNamed:[self.venueThumbnails objectAtIndex:indexPath.item]]; cell.venueNameLabel.text = [self.venueNames objectAtIndex:indexPath.item]; cell.venueNameLabel.textColor = [UIColor whiteColor]; cell.venueAddressLabel.text = [self.venueAddresses objectAtIndex:indexPath.item]; cell.venueAddressLabel.textColor = [UIColor whiteColor]; [cell setBackgroundColor:[[UIColor grayColor]colorWithAlphaComponent:.1]]; return cell; }
在包含innerCollectionView细胞实现文件
-(FeaturedEventCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { FeaturedEventCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"FeaturedEventCellReuseIdentifier" forIndexPath:indexPath]; cell.eventDateLabel.text = [self.events objectAtIndex:indexPath.item]; cell.eventDateLabel.textColor = [UIColor whiteColor]; cell.eventImage.image = [UIImage imageNamed:[NSString stringWithFormat:@"%@Flyer%ld.png", self.venueNameLabel.text, (long)indexPath.item +1]]; return cell; }
在这个代码块我使用含电池的标签的值来加载有关该单元格数据为innerCollectionView。
非常直截了当的实现。 其结果是不是我所期待的。 基本上发生的事情是,数据被正确地加载到outerCollectionView的细胞,但不进innerCollectionView的细胞(极第一个得到正确加载,但其中不休息)。 还通过innerCollectionView项目滚动会导致滚动在细胞中的其余部分。
我认为,让细胞含有innerCollectionView的代表将负责管理它独立的自己的集合视图从别人。 我觉得我不理解一些关于收集意见的根本,出队和重用。
还嵌套集合视图我的方案的实施的一个好办法吗? 我试图查找在执行嵌套的收集意见,并不能找到,也许一大堆的理由吗?
请解释什么,我在我的情况做错了或直接向我正确的或者更好的解决方案。