4

У меня есть подкласс UIView, который имеет динамически созданный UICollectionView. Все отлично работает в ios7 с отображением заголовков просто отлично.Заголовок заголовка UICollectionView сбой iOS 8

iOS 8 не вызывает этот метод вообще, и приложение выходит из строя.

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath 

Если я закомментировать этот метод, и я настроен на размер заголовка/нижнего колонтитула 0, IOS 8 не врезаться больше.

Вот код, чтобы создать представление коллекции:

int spacing = 39; 

UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init]; 
layout.itemSize = CGSizeMake(199, 60); 
if (IS_IOS8) layout.estimatedItemSize = CGSizeMake(199, 60); 
layout.scrollDirection = UICollectionViewScrollDirectionVertical; 
layout.minimumInteritemSpacing = 1; 
layout.minimumLineSpacing = 1; 
layout.sectionInset = UIEdgeInsetsMake(1,1,1,1); 
layout.headerReferenceSize = CGSizeMake(self.width - spacing*2, 50.0f); 
layout.footerReferenceSize = CGSizeZero; 

self.collectionView=[[UICollectionView alloc] initWithFrame:CGRectMake(spacing, 5, self.width - spacing*2, self.height - spacing*2) collectionViewLayout:layout]; 

self.collectionView.dataSource = self; 
self.collectionView.delegate = self; 

[self.collectionView registerClass:[OCEListCell class] forCellWithReuseIdentifier:CellIdentifier]; 
[self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:HeaderCellIdentifier]; 
[self.collectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:FooterCellIdentifier]; 
self.collectionView.backgroundColor = [UIColor clearColor]; 


[self addSubview:self.collectionView]; 

Источник данных Методы:

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath 
{ 
    UICollectionReusableView * view = nil; 

    NSLog(@"viewForSupplementaryElementOfKind"); 
    if ([kind isEqualToString:UICollectionElementKindSectionHeader]) 
    { 
     view = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:HeaderCellIdentifier forIndexPath:indexPath]; 
     view.backgroundColor = [UIColor clearColor]; 

     UILabel * lbl = [[UILabel alloc] initWithFrame:CGRectMake(0, 15, view.width, 40)]; 
     lbl.textColor = [UIColor defaultTextColor]; 
     lbl.font = [UIFont bookFontOfSize:25.0f]; 
     lbl.numberOfLines = 1; 
     lbl.text = indexPath.section == 0 ? @"Section 1 Header" : @"Section 2 Header"; 
     [view addSubview:lbl]; 
    } 
    else if ([kind isEqualToString:UICollectionElementKindSectionFooter]) 
    { 
     view = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:FooterCellIdentifier forIndexPath:indexPath]; 
     view.backgroundColor = [UIColor clearColor]; 
    } 

    NSLog(@"viewForSupplementaryElementOfKind:%@", view); 
    return view; 
} 



-(CGSize) collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section 
{ 
    CGSize size = CGSizeMake(collectionView.width, 50); 
    NSLog(@"referenceSizeForHeaderInSection: %@", NSStringFromCGSize(size)); 
    return size; 
} 


-(CGSize) collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section 
{ 
    CGSize size = CGSizeZero; 
    NSLog(@"referenceSizeForFooterInSection: %@", NSStringFromCGSize(size)); 
    return size; 
} 
+0

Что такое сообщение об аварии? – shawnwall

+0

К сожалению, я даже не получаю трассировку стека. Я пробовал символические точки останова и обработчики исключений по умолчанию. Я использую библиотеку для аналитики, и они показывают журнал сбоев, который: Завершение приложения из-за неперехваченного исключения «NSInvalidArgumentException», причина: «*** - [__ NSArrayM insertObject: atIndex:]: объект не может быть nil ' Я не вызываю insertObject где-нибудь там, поэтому я не был уверен, что это был точный журнал сбоев –

+2

Я уверен, что это ошибка. http://stackoverflow.com/questions/25460323/why-does-using-headerreferencesize-with-self-sizing-cells-in-a-collection-view-c –

ответ

1

Я только что вернулся, чтобы смотреть на это снова, как я был в состоянии получить верхние и нижние колонтитулы несколько раз работая в разных представлениях и выяснил, что проблема с этим конкретным представлением заключается в установке параметра оценки.

Комментируя эту линию избавившись от моих неприятностей:

if (IS_IOS8) layout.estimatedItemSize = CGSizeMake(177, 60); 

Это было разочарование вещь, чтобы диагностировать, потому что никаких ошибок, предупреждений компилятора и т.д. не дали никакой информации.

+0

Пожалуйста, откройте отчет об ошибке. – DrMickeyLauer

Смежные вопросы