Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 从UICollectionView(或其他方向)获取节索引_Objective C_Uicollectionview_Nsfetchedresultscontroller - Fatal编程技术网

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;
}
原贴于此: