iOSpipe理嵌套的UICollectionViews问题
我在处理嵌套的集合视图时遇到了一个问题。 层次如下:
- 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委托将独立于其他人pipe理它自己的集合视图。 我认为我不了解关于收集意见,出院和重复使用的一些基本的东西。
嵌套集合也是实现我的场景的好方法吗? 我试图查看实现嵌套的集合视图,并找不到一大堆可能是一个原因?
请解释一下我在做什么错,或者指导我走向正确或者更好的解决scheme。