Ios7 UICollection视图删除节

Ios7 UICollection视图删除节,ios7,xcode5,uicollectionview,Ios7,Xcode5,Uicollectionview,我已经搜索了很多,以找到在UICollectionView中删除节的解决方案 但所有提出的解决方案都会导致崩溃 我使用的代码是: [categoryCollection performBatchUpdates:^{ NSIndexSet *indexSet=[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, keys.count-1)]; [categoryCollection deleteSections:

我已经搜索了很多,以找到在UICollectionView中删除节的解决方案 但所有提出的解决方案都会导致崩溃

我使用的代码是:

[categoryCollection performBatchUpdates:^{
        NSIndexSet *indexSet=[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, keys.count-1)];
        [categoryCollection deleteSections:indexSet];

    } completion:nil];
更新:

 @implementation BooksLayout
 - (void)prepareLayout {
// Registers my decoration views.
[self registerClass:[ShelfView class] forDecorationViewOfKind:[ShelfView kind]];
 }

 - (UICollectionViewLayoutAttributes *)layoutAttributesForDecorationViewOfKind:(NSString  *)decorationViewKind atIndexPath:(NSIndexPath *)indexPath {
// Prepare some variables.
NSIndexPath *nextIndexPath = [NSIndexPath indexPathForItem:indexPath.row+1 inSection:indexPath.section];

UICollectionViewLayoutAttributes *cellAttributes = [self layoutAttributesForItemAtIndexPath:indexPath];
UICollectionViewLayoutAttributes *nextCellAttributes = [self layoutAttributesForItemAtIndexPath:nextIndexPath];

UICollectionViewLayoutAttributes *layoutAttributes = [UICollectionViewLayoutAttributes layoutAttributesForDecorationViewOfKind:decorationViewKind withIndexPath:indexPath];

CGRect baseFrame = cellAttributes.frame;
CGRect nextFrame = nextCellAttributes.frame;

CGFloat strokeWidth = 8;
CGFloat spaceToNextItem = 0;
if (nextFrame.origin.y == baseFrame.origin.y)
    spaceToNextItem = (nextFrame.origin.x - baseFrame.origin.x - baseFrame.size.width);

// Positions the horizontal line for this item.
    layoutAttributes.frame = CGRectMake(10,
                                        baseFrame.origin.y + baseFrame.size.height,
                                        300,
                                        strokeWidth);


layoutAttributes.zIndex = 1;
return layoutAttributes;
}

- (NSArray *)layoutAttributesForElementsInRect:(CGRect)rect {
NSArray *baseLayoutAttributes = [super layoutAttributesForElementsInRect:rect];
NSMutableArray * layoutAttributes = [baseLayoutAttributes mutableCopy];

for (UICollectionViewLayoutAttributes *thisLayoutItem in baseLayoutAttributes) {
    if (thisLayoutItem.representedElementCategory == UICollectionElementCategoryCell) {
            UICollectionViewLayoutAttributes *newHorizontalLayoutItem = [self layoutAttributesForDecorationViewOfKind:[ShelfView kind] atIndexPath:thisLayoutItem.indexPath];
            [layoutAttributes addObject:newHorizontalLayoutItem];

    }
}

return layoutAttributes;
}
 -(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
if([sortString isEqualToString:@"title"]){
    NSArray *keys=[bookObj.orderedBooks allKeys];
    keys = [keys sortedArrayUsingSelector:
            @selector(localizedCaseInsensitiveCompare:)];
    return [[bookObj.orderedBooks objectForKey:[keys objectAtIndex:section]] count];
}
else
    return bookObj.booksArray.count;
}

可能重复我尝试了该解决方案,将委托设置为nil,但仍然会发生崩溃。是否可以添加崩溃日志?在-[UICollectionViewData NumberOfItemsBeforeCompression:]、/SourceCache/UIKit_Sim/UIKit-2935.137/UICollectionViewData.m:514由于未捕获的异常“NSInternalInconsistencyException”终止应用程序,原因:“当集合视图中只有1个节时,请求第4节之前的项数”可以添加集合视图数据源方法的代码。