Skip to content

Commit

Permalink
fix(ios): make Ti.UI.PickerColumn.rowCount NSNumber*, not NSInteger
Browse files Browse the repository at this point in the history
theoretically this should avoid crash
  • Loading branch information
sgtcoolguy committed Oct 28, 2020
1 parent c277024 commit 026fe12
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion iphone/Classes/TiUIPicker.m
Expand Up @@ -330,7 +330,7 @@ - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
TiUIPickerColumnProxy *proxy = [[self columns] objectAtIndex:component];
return [proxy rowCount];
return proxy.rowCount.integerValue;
}

#pragma mark Delegates (only for UIPickerView)
Expand Down
4 changes: 2 additions & 2 deletions iphone/Classes/TiUIPickerColumnProxy.h
Expand Up @@ -14,12 +14,12 @@
}

@property (nonatomic, readonly) NSMutableArray *rows;
@property (nonatomic, readonly) NSInteger rowCount;
@property (nonatomic, readonly) NSNumber *rowCount;
@property (nonatomic, readwrite, assign) NSInteger column;

- (NSNumber *)addRow:(id)row;
- (void)removeRow:(id)row;
- (id)rowAt:(NSInteger)row;
- (id)rowAt:(NSUInteger)row;

@end
#endif
6 changes: 3 additions & 3 deletions iphone/Classes/TiUIPickerColumnProxy.m
Expand Up @@ -31,12 +31,12 @@ - (NSMutableArray *)rows
return [[rows copy] autorelease];
}

- (NSInteger)rowCount
- (NSNumber *)rowCount
{
return [rows count];
return NUMUINTEGER((rows != nil) ? rows.count : 0);
}

- (id)rowAt:(NSInteger)index
- (id)rowAt:(NSUInteger)index
{
return (index < [rows count]) ? [rows objectAtIndex:index] : nil;
}
Expand Down
15 changes: 10 additions & 5 deletions iphone/Classes/TiUIPickerProxy.m
Expand Up @@ -83,7 +83,8 @@ - (void)windowWillOpen
// Tell all of the picker bits that their window has opened. Can't operate
// on the rows array directly; they're returned as a copy from the column.
for (TiUIPickerColumnProxy *column in [self columns]) {
for (NSInteger i = 0; i < [column rowCount]; i++) {
NSUInteger rowCount = column.rowCount.unsignedIntegerValue;
for (NSUInteger i = 0; i < rowCount; i++) {
[[column rowAt:i] windowWillOpen];
}
}
Expand Down Expand Up @@ -138,7 +139,8 @@ - (void)addPickerColumn:(NSDictionary *)params
NSMutableArray *columns = [params objectForKey:@"columns"];
TiUIPickerColumnProxy *column = [params objectForKey:@"column"];
if (windowOpened) {
for (NSInteger i = 0; i < [column rowCount]; i++) {
NSUInteger rowCount = column.rowCount.unsignedIntegerValue;
for (NSUInteger i = 0; i < rowCount; i++) {
TiUIPickerRowProxy *row = [column rowAt:i];

[row windowWillOpen];
Expand All @@ -154,10 +156,13 @@ - (void)addRowOfColumns:(NSDictionary *)params
{
ENSURE_UI_THREAD_1_ARG(params);
NSMutableArray *columns = [params objectForKey:@"columns"];
NSArray *data = [params objectForKey:@"data"];
for (id column in data) {
NSArray<TiUIPickerColumnProxy *> *data = [params objectForKey:@"data"];
for (TiUIPickerColumnProxy *column in data) {
if (windowOpened) {
for (NSInteger i = 0; i < [column rowCount]; i++) {
ENSURE_TYPE(column, TiUIPickerColumnProxy);

NSUInteger rowCount = column.rowCount.unsignedIntegerValue;
for (NSUInteger i = 0; i < rowCount; i++) {
TiUIPickerRowProxy *row = [column rowAt:i];

[row windowWillOpen];
Expand Down

0 comments on commit 026fe12

Please sign in to comment.