dequeueReusableSupplementaryViewOfKind在ios 7.1上崩溃 - 索引0超出空数组的界限 [英] dequeueReusableSupplementaryViewOfKind crash on ios 7.1 - index 0 beyond bounds for empty array

查看:2898
本文介绍了dequeueReusableSupplementaryViewOfKind在ios 7.1上崩溃 - 索引0超出空数组的界限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有两个部分的集合视图。

having a collection view with 2 sections.

section 1:
rows: 0


section 2:
rows: 20

[self.collectionView registerNib:[UINib nibWithNibName:@"MissionDetailHeader" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"MissionDetailHeader"];
[self.collectionView registerNib:[UINib nibWithNibName:@"MissionDetailHeaderPic" bundle:nil] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"MissionDetailHeaderPic"];

在ios8上工作完美,但在7.1它总是崩溃 dequeueReusableSupplementaryViewOfKind

works perfect on ios8 - but on 7.1 it always crashes at dequeueReusableSupplementaryViewOfKind:

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

    UICollectionReusableView* header;

    NSLog(@"LOAD SECT: %@", indexPath);
    if (indexPath.section == 0) {

        header = [collectionView dequeueReusableSupplementaryViewOfKind:kind
                                                                              withReuseIdentifier:@"MissionDetailHeaderPic"
                                                                                     forIndexPath:indexPath];

    } else {
        header = [collectionView dequeueReusableSupplementaryViewOfKind:kind
                                                    withReuseIdentifier:@"MissionDetailHeader"
                                                           forIndexPath:indexPath];
    }
    return header;
}

Stacktrace:

Stacktrace:

*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 0 beyond bounds for empty array'
*** First throw call stack:
(
    0   CoreFoundation                      0x047c61e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x009f98e5 objc_exception_throw + 44
    2   CoreFoundation                      0x047673f6 -[__NSArrayM objectAtIndex:] + 246
    3   UIKit                               0x03d18750 -[UICollectionViewFlowLayout(Internal) _frameForHeaderInSection:usingData:] + 61
    4   UIKit                               0x03d14afa -[UICollectionViewFlowLayout layoutAttributesForHeaderInSection:usingData:] + 61
    5   UIKit                               0x03d15687 -[UICollectionViewFlowLayout layoutAttributesForSupplementaryViewOfKind:atIndexPath:] + 192
    6   UIKit                               0x03d2f02a -[UICollectionViewData layoutAttributesForSupplementaryElementOfKind:atIndexPath:] + 363
    7   UIKit                               0x03cf9764 -[UICollectionView _dequeueReusableViewOfKind:withIdentifier:forIndexPath:viewCategory:] + 242
    8   UIKit                               0x03cfa00a -[UICollectionView dequeueReusableSupplementaryViewOfKind:withReuseIdentifier:forIndexPath:] + 239
    9   fivexfive                           0x00102e33 -[MissionDetailViewController collectionView:viewForSupplementaryElementOfKind:atIndexPath:] + 243
    10  UIKit                               0x03cec099 -[UICollectionView _createPreparedSupplementaryViewForElementOfKind:atIndexPath:withLayoutAttributes:applyAttributes:] + 480
    11  UIKit                               0x03ced775 -[UICollectionView _updateVisibleCellsNow:] + 4730
    12  UIKit                               0x03cf165f -[UICollectionView layoutSubviews] + 265
    13  UIKit                               0x03714964 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
    14  libobjc.A.dylib                     0x00a0b82b -[NSObject performSelector:withObject:] + 70
    15  QuartzCore                          0x0342b45a -[CALayer layoutSublayers] + 148
    16  QuartzCore                          0x0341f244 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380

已搜索过SO和googled like hell - 找不到任何提示/提示如何追踪错误。

already searched around SO and googled like hell - cannot find any hint/tip how to trace down the error.

关于
helmut

regards helmut

推荐答案

OK answer myself:D

ok answer myself :D

删除

 [self.stretchyLayout setSectionInset:UIEdgeInsetsMake(8, 8, 0, 8)];

所有对setSectionInset的调用 - 已在ios7上修复

all calls to setSectionInset - fixed it on ios7

这篇关于dequeueReusableSupplementaryViewOfKind在ios 7.1上崩溃 - 索引0超出空数组的界限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆