Skip to content

Commit

Permalink
Merge pull request #625 from compositeprimes/master
Browse files Browse the repository at this point in the history
Fix crash in NICollectionViewModel/TableViewModel
  • Loading branch information
jverkoey committed Sep 30, 2015
2 parents f052a33 + 3386b29 commit 54d2146
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/collections/src/NICollectionViewModel+Private.h
Expand Up @@ -25,6 +25,7 @@
- (void)_resetCompiledData;
- (void)_compileDataWithListArray:(NSArray *)listArray;
- (void)_compileDataWithSectionedArray:(NSArray *)sectionedArray;
- (void)_setSectionsWithArray:(NSArray *)sectionsArray;

@end

Expand Down
10 changes: 7 additions & 3 deletions src/collections/src/NICollectionViewModel.m
Expand Up @@ -59,7 +59,7 @@ - (id)init {


- (void)_resetCompiledData {
self.sections = nil;
[self _setSectionsWithArray:nil];
self.sectionIndexTitles = nil;
self.sectionPrefixToSectionIndex = nil;
}
Expand All @@ -70,7 +70,7 @@ - (void)_compileDataWithListArray:(NSArray *)listArray {
if (nil != listArray) {
NICollectionViewModelSection* section = [NICollectionViewModelSection section];
section.rows = listArray;
self.sections = [NSArray arrayWithObject:section];
[self _setSectionsWithArray:@[ section ]];
}
}

Expand Down Expand Up @@ -132,7 +132,11 @@ - (void)_compileDataWithSectionedArray:(NSArray *)sectionedArray {
currentSectionRows = nil;

// Update the compiled information for this data source.
self.sections = sections;
[self _setSectionsWithArray:sections];
}

- (void)_setSectionsWithArray:(NSArray *)sectionsArray {
self.sections = sectionsArray;
}

#pragma mark - UICollectionViewDataSource
Expand Down
8 changes: 8 additions & 0 deletions src/collections/src/NIMutableCollectionViewModel.m
Expand Up @@ -121,6 +121,14 @@ - (NICollectionViewModelSection *)_insertSectionAtIndex:(NSUInteger)index {
return section;
}

- (void)_setSectionsWithArray:(NSArray *)sectionsArray {
if ([sectionsArray isKindOfClass:[NSMutableArray class]]) {
self.sections = (NSMutableArray *)sectionsArray;
} else {
self.sections = [sectionsArray mutableCopy];
}
}

@end


Expand Down
12 changes: 10 additions & 2 deletions src/models/src/NIMutableTableViewModel.m
Expand Up @@ -99,7 +99,7 @@ - (void)updateSectionIndex {

- (NITableViewModelSection *)_appendSection {
if (nil == self.sections) {
self.sections = [NSMutableArray array];
[self _setSectionsWithArray:[NSMutableArray array]];
}
NITableViewModelSection* section = nil;
section = [[NITableViewModelSection alloc] init];
Expand All @@ -110,7 +110,7 @@ - (NITableViewModelSection *)_appendSection {

- (NITableViewModelSection *)_insertSectionAtIndex:(NSUInteger)index {
if (nil == self.sections) {
self.sections = [NSMutableArray array];
[self _setSectionsWithArray:[NSMutableArray array]];
}
NITableViewModelSection* section = nil;
section = [[NITableViewModelSection alloc] init];
Expand All @@ -120,6 +120,14 @@ - (NITableViewModelSection *)_insertSectionAtIndex:(NSUInteger)index {
return section;
}

- (void)_setSectionsWithArray:(NSArray *)sectionsArray {
if ([sectionsArray isKindOfClass:[NSMutableArray class]]) {
self.sections = (NSMutableArray *)sectionsArray;
} else {
self.sections = [sectionsArray mutableCopy];
}
}

#pragma mark - UITableViewDataSource


Expand Down
1 change: 1 addition & 0 deletions src/models/src/NITableViewModel+Private.h
Expand Up @@ -26,6 +26,7 @@
- (void)_compileDataWithListArray:(NSArray *)listArray;
- (void)_compileDataWithSectionedArray:(NSArray *)sectionedArray;
- (void)_compileSectionIndex;
- (void)_setSectionsWithArray:(NSArray *)sectionsArray;

@end

Expand Down
10 changes: 7 additions & 3 deletions src/models/src/NITableViewModel.m
Expand Up @@ -65,7 +65,7 @@ - (id)init {


- (void)_resetCompiledData {
self.sections = nil;
[self _setSectionsWithArray:nil];
self.sectionIndexTitles = nil;
self.sectionPrefixToSectionIndex = nil;
}
Expand All @@ -76,7 +76,7 @@ - (void)_compileDataWithListArray:(NSArray *)listArray {
if (nil != listArray) {
NITableViewModelSection* section = [NITableViewModelSection section];
section.rows = [listArray mutableCopy];
self.sections = [NSMutableArray arrayWithObject:section];
[self _setSectionsWithArray:@[ section ]];
}
}

Expand Down Expand Up @@ -138,7 +138,7 @@ - (void)_compileDataWithSectionedArray:(NSArray *)sectionedArray {
currentSectionRows = nil;

// Update the compiled information for this data source.
self.sections = sections;
[self _setSectionsWithArray:sections];
}

- (void)_compileSectionIndex {
Expand Down Expand Up @@ -222,6 +222,10 @@ - (void)_compileSectionIndex {
self.sectionPrefixToSectionIndex = sectionPrefixToSectionIndex;
}

- (void)_setSectionsWithArray:(NSArray *)sectionsArray {
self.sections = sectionsArray;
}

#pragma mark - UITableViewDataSource


Expand Down

0 comments on commit 54d2146

Please sign in to comment.