I have a data model called Location. I use them as section headers in UICollectionViewController. Everyone Locationcan display itemsinside these sections. I want to customize the section headers in viewForSupplementaryElementOfKind. But I cannot figure out how to extract the correct objects from this method Location.
I tried things like:
-(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath
{
id <NSFetchedResultsSectionInfo> sectionInfo = [self.fetchedResultsController sections] [indexPath.section];
Item *item = sectionInfo.objects[0];
Location *location = item.location;
SectionHeaderView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"SectionHeader" forIndexPath:indexPath];
headerView.label.text = location.name;
[...]
But I keep getting:
Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'
Perhaps this is due to the fact that it is possible to place without any elements. Any other ideas on how I should do this?
source
share