Skip to content
This repository has been archived by the owner on Feb 16, 2019. It is now read-only.

Commit

Permalink
Clear section cache info when deleting sections to avoid out of bound…
Browse files Browse the repository at this point in the history
…s crash.
  • Loading branch information
baz committed Feb 13, 2012
1 parent 05f1e5e commit c0b78be
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion SSToolkit/SSCollectionView.m
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,10 @@ - (void)insertSections:(NSIndexSet *)sections withItemAnimation:(SSCollectionVie


- (void)deleteSections:(NSIndexSet *)sections withItemAnimation:(SSCollectionViewItemAnimation)animation {
// Clear cached number of items in the deleted sections because to avoid an out of bounds crash when inserting a new section in place of the deleted one
[sections enumerateIndexesUsingBlock:^(NSUInteger index, BOOL *stop) {
[self _setSectionInfoItem:nil forKey:kSSCollectionViewSectionNumberOfItemsKey section:index];
}];
[_tableView deleteSections:sections withRowAnimation:(UITableViewRowAnimation)animation];
}

Expand Down Expand Up @@ -660,7 +664,7 @@ - (NSArray *)_itemsForRowIndexPath:(NSIndexPath *)rowIndexPath {
NSUInteger startIndex = itemsPerRow * row;
NSUInteger endIndex = (NSUInteger)fmin(totalItems, startIndex + itemsPerRow);

NSMutableArray *items = [[[NSMutableArray alloc] initWithCapacity:endIndex - startIndex] autorelease];
NSMutableArray *items = [[[NSMutableArray alloc] initWithCapacity:abs(endIndex - startIndex)] autorelease];

for (NSUInteger i = startIndex; i < endIndex; i++) {
NSIndexPath *itemIndexPath = [NSIndexPath indexPathForRow:i inSection:rowIndexPath.section];
Expand Down

0 comments on commit c0b78be

Please sign in to comment.