Skip to content

Commit

Permalink
fix(ios): TableView "sectionCount" property crash (#12193)
Browse files Browse the repository at this point in the history
  • Loading branch information
jquick-axway committed Oct 21, 2020
1 parent 318f35a commit 149eb4a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
9 changes: 5 additions & 4 deletions iphone/Classes/TiUITableView.m
Expand Up @@ -555,7 +555,7 @@ - (void)replaceData:(NSMutableArray *)data animation:(UITableViewRowAnimation)an
//won't have any problems in the case that it is actually nil.
TiUITableViewProxy *ourProxy = (TiUITableViewProxy *)[self proxy];

NSUInteger oldCount = [ourProxy sectionCount];
NSUInteger oldCount = ourProxy.sectionCount.unsignedIntegerValue;

for (TiUITableViewSectionProxy *section in [(TiUITableViewProxy *)[self proxy] internalSections]) {
if ([section parent] == ourProxy) {
Expand Down Expand Up @@ -1313,7 +1313,8 @@ - (void)updateSearchResultIndexes
}
NSEnumerator *searchResultIndexEnumerator;
if (searchResultIndexes == nil) {
searchResultIndexes = [[NSMutableArray alloc] initWithCapacity:[(TiUITableViewProxy *)[self proxy] sectionCount]];
NSUInteger sectionCount = [(TiUITableViewProxy *)[self proxy] sectionCount].unsignedIntegerValue;
searchResultIndexes = [[NSMutableArray alloc] initWithCapacity:sectionCount];
searchResultIndexEnumerator = nil;
} else {
searchResultIndexEnumerator = [searchResultIndexes objectEnumerator];
Expand Down Expand Up @@ -2124,7 +2125,7 @@ - (NSInteger)numberOfSectionsInTableView:(UITableView *)ourTableView
return 1;
}
// One quirk of UITableView is that it really hates having 0 sections. Instead, supply 1 section, no rows.
NSUInteger result = [(TiUITableViewProxy *)[self proxy] sectionCount];
NSUInteger result = [(TiUITableViewProxy *)[self proxy] sectionCount].unsignedIntegerValue;
return MAX(1, result);
}

Expand Down Expand Up @@ -2166,7 +2167,7 @@ - (void)tableView:(UITableView *)ourTableView commitEditingStyle:(UITableViewCel
[table beginUpdates];
if (emptySection) {
NSIndexSet *thisSectionSet = [NSIndexSet indexSetWithIndex:[indexPath section]];
if ([(TiUITableViewProxy *)[self proxy] sectionCount] > 0) {
if ([(TiUITableViewProxy *)[self proxy] sectionCount].unsignedIntegerValue > 0) {
[table deleteSections:thisSectionSet withRowAnimation:UITableViewRowAnimationFade];
} else //There always must be at least one section. So instead, we have it reload to clear out the header and footer, etc.
{
Expand Down
2 changes: 1 addition & 1 deletion iphone/Classes/TiUITableViewProxy.h
Expand Up @@ -21,7 +21,7 @@
- (NSArray *)data;
//Sections and Data are the sanitized version.
@property (nonatomic, readwrite, copy) NSArray *sections;
- (NSUInteger)sectionCount;
- (NSNumber *)sectionCount;

#pragma mark NON-JS functionality
//internalSections is until TODO: Stop JS from using ValueForKey
Expand Down
4 changes: 2 additions & 2 deletions iphone/Classes/TiUITableViewProxy.m
Expand Up @@ -882,9 +882,9 @@ - (void)willShow
[(TiUITableView *)[self view] refreshSearchControllerUsingReload:YES];
}

- (NSUInteger)sectionCount
- (NSNumber *)sectionCount
{ //TODO: Shouldn't this be in the main thread, too?
return [sections count];
return NUMUINTEGER((sections != nil) ? sections.count : 0);
}

- (TiUITableViewSectionProxy *)tableSectionFromArg:(id)arg
Expand Down

0 comments on commit 149eb4a

Please sign in to comment.