Layout UICollectionView布局属性ForElementsRect不返回可重用视图
我正在尝试使用补充视图实现UICollectionView。 我使用Nib文件创建补充视图。以下是布局中添加补充视图的方法:Layout UICollectionView布局属性ForElementsRect不返回可重用视图,layout,view,ios6,uicollectionview,supplementary,Layout,View,Ios6,Uicollectionview,Supplementary,我正在尝试使用补充视图实现UICollectionView。 我使用Nib文件创建补充视图。以下是布局中添加补充视图的方法: NSMutableArray *attributesInRect = [[super layoutAttributesForElementsInRect:rect] mutableCopy]; NSLog(@"%@", attributesInRect); if ([self.collectionView numberOfItemsInSection:0] &g
NSMutableArray *attributesInRect = [[super layoutAttributesForElementsInRect:rect] mutableCopy];
NSLog(@"%@", attributesInRect);
if ([self.collectionView numberOfItemsInSection:0] > 1 && !self.selectedItem)
{
if ([self.musicList count] > 0)
{
UICollectionViewLayoutAttributes *musicViewAttributes = [self layoutAttributesForSupplementaryViewOfKind:@"MusicView" atIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]];
musicViewAttributes.size = CGSizeMake(CGRectGetWidth([[UIScreen mainScreen] bounds]), 150);
musicViewAttributes.center = CGPointMake(musicViewAttributes.size.width/2, musicViewAttributes.size.height/2);
musicViewAttributes.zIndex = 0;
[attributesInRect addObject:musicViewAttributes];
}
}
return attributesInRect;
不要注意这里的条件,只关注属性数组(attributesInRect)。当我这样做时,我的补充内容将正确地添加到CollectionView中
我的问题是检索添加的补充视图。在NSLog上,我的补充视图没有列在数组中。在这种情况下,在添加新的之前,我无法检查它是否存在
我真的不明白为什么文档中规定:
返回值
UICollectionViewLayoutAttribute对象数组,表示单元格和视图的布局信息。默认实现返回nil
根据这一点,我的补充意见应该在该数组中
对此有何想法?经过进一步调查,只有在我调用PerformBatchUpdate时,问题才会出现