Ios 将数据传递到UICollectionReusableView
我正在使用自定义UICollectionViewFlowLayout,并且我已经为此布局注册了自定义的可重用类Ios 将数据传递到UICollectionReusableView,ios,objective-c,uicollectionview,Ios,Objective C,Uicollectionview,我正在使用自定义UICollectionViewFlowLayout,并且我已经为此布局注册了自定义的可重用类 [self registerClass:[noContentDecoration class] forDecorationViewOfKind:knoContentsDecorationKind]; 现在,我想在初始化阶段向这个装饰视图传递一些数据,我想在这个可重用类中设置一些属性 但我无法访问此视图,我只找到UICollectionView的此委托方法: - (void)coll
[self registerClass:[noContentDecoration class] forDecorationViewOfKind:knoContentsDecorationKind];
现在,我想在初始化阶段向这个装饰视图传递一些数据,我想在这个可重用类中设置一些属性
但我无法访问此视图,我只找到UICollectionView的此委托方法:
- (void)collectionView:(UICollectionView *)collectionView didEndDisplayingSupplementaryView:(UICollectionReusableView *)view forElementOfKind:(NSString *)elementKind atIndexPath:(NSIndexPath *)indexPath
但这里的问题是:此方法仅在文档中提到的删除可重用视图时调用:
使用此方法可以检测何时从集合视图中删除补充视图,而不是监视视图本身以查看它何时出现或消失
如何在初始化过程中将数据传递给这个可重用视图
谢谢您正在使用装饰视图。向它传递数据是复杂的
UICollectionViewLayoutAttribute的自定义子类来保存数据
UICollectionViewLayout
子类中,重写LayoutAttributeClass
以返回自定义属性类UICollectionViewLayout
子类中,在LayoutAttributesForElementsRect:
和layoutAttributesForDecorationViewOfKind:atIndexPath:
中正确设置装饰视图的属性noContentDecoration
)中,重写applyLayoutAttributes:
以从attributes对象中提取数据并应用它们UICollectionViewDataSource
(可能是您的视图控制器)中,实现collectionView:ViewForSupplmentalElementOfKind:atIndexPath:
以获取视图(使用DequeueReusableSupplmentaryViewOfKind:withReuseIdentifier:forIndexPath:
),然后使用数据设置它,然后返回它