Objective c 从UICollectionView(或其他方向)获取节索引
给定节索引,如何获取节标题的Objective c 从UICollectionView(或其他方向)获取节索引,objective-c,uicollectionview,nsfetchedresultscontroller,Objective C,Uicollectionview,Nsfetchedresultscontroller,给定节索引,如何获取节标题的UICollectionReusableView 或者如何从UICollectionReusableView对象获取节索引 我读过这样的文章:,和类似的文章,但对我来说不起作用 My Section由一个NSFetchedResultsController动态控制,有多个插入、删除和重新插入。我怀疑我存储在collectionView:viewforsupplementalelementofkind:atIndexPath和collectionView:dienddi
UICollectionReusableView
或者如何从UICollectionReusableView
对象获取节索引
我读过这样的文章:,和类似的文章,但对我来说不起作用
My Section由一个
NSFetchedResultsController
动态控制,有多个插入、删除和重新插入。我怀疑我存储在collectionView:viewforsupplementalelementofkind:atIndexPath
和collectionView:dienddisplayingsupplementview:forElementOfKind:atIndexPath:
中的索引在某个点上无效 最终我找到了解决办法。丑陋但似乎有效:
- (SUGalleryHeaderView *)headerForSection:(NSInteger)section
{
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:section];
NSString *kind = UICollectionElementKindSectionHeader;
UICollectionViewLayoutAttributes *attr =
[self.collectionViewLayout layoutAttributesForSupplementaryViewOfKind:kind atIndexPath:indexPath];
for (SUGalleryHeaderView *header in headersActive) {
if (CGRectEqualToRect(header.frame, attr.frame)) {
return header;
}
}
return nil;
}
原贴于此: