Uipicker crash when spinning 2 components simultaneuosly

147 Views Asked by At

The below code creates a crash if i spin 2 components at the same time as occasionally depending which arrays are selected, the values will be out of bounds

i need some condition checking which will stop the crash but dont know what how

can anyone advise suitable code that will handle the condition to avoid the crash

thanks

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{

    // Only calls the following code if component "0" has changed.
        if (component == 0) 
        {

            // Sets the global integer "component0Row" to the currently selected row of component "0"
            component0Row  = row;

            // Loads the new values for the selector into a new array in order to reload the data.
            NSDictionary *newDict = [[NSDictionary alloc]initWithDictionary:[pickerData objectForKey:[Letters objectAtIndex:component0Row]]];

            NSArray *sortArray = [[NSArray alloc]initWithArray:[newDict allKeys]];

            NSMutableArray *newValues = [[NSMutableArray alloc]initWithArray:[sortArray sortedArrayUsingSelector:@selector(localizedStandardCompare:)]];

            self.Numbers = newValues;

            component1Row = 0;
            [self.myPicker selectRow:0 inComponent:1 animated:NO];

            [newDict release];
            [sortArray release];
            [newValues release];
        }
        if(component ==1)
        {
            component0Row = [pickerView selectedRowInComponent:0];
            component1Row =row;
        }
}
1

There are 1 best solutions below

2
On

Problem could be in titleForRow method or numberOfRows method. You have to make sure you are not beyond the bounds of the array in question.