2013-07-26 3 views
2

Я пытаюсь добавить нижний колонтитул в UICollectionView.UICollectionView Footer

Ниже мой код,

UICollectionView добавляется через IB

В viewDidLoad зарегистрироваться колонтитула,

[mCollectionView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"footer"]; 

и реализован следующий метод

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

    if (kind == UICollectionElementKindSectionFooter) { 
     UICollectionReusableView *headerView = [mCollectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"footer" forIndexPath:indexPath]; 

     [headerView addSubview:mFooterView]; 
     reusableview = headerView; 
    } 
    return reusableview; 
} 

Но мои приложения продолжать сбой, а ниже - журнал,

*** отказ Assertion в - [UICollectionView _dequeueReusableViewOfKind: withIdentifier: forIndexPath:], /SourceCache/UIKit/UIKit-2380.17/UICollectionView.m:2249

Любая помощь приветствуется.

Спасибо.

ответ

9

в вашем коде, почему вы просматриваете заголовок и добавляете нижний колонтитул к нему?

нормальная реализация этого метода:

- (UICollectionReusableView *)collectionView:(UICollectionView *)theCollectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)theIndexPath 
{ 

    UICollectionReusableView *theView; 

    if(kind == UICollectionElementKindSectionHeader) 
    { 
     theView = [theCollectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"header" forIndexPath:theIndexPath]; 
    } else { 
     theView = [theCollectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"footer" forIndexPath:theIndexPath]; 
    } 

    return theView; 
} 
+0

Да, я сделал то же самое, и это сработало для меня !! Я отметит свой ответ, как правильно –