如果我同时旋转 2 个组件,以下代码会导致崩溃,有时取决于选择了哪些数组,这些值将超出范围
我需要一些条件检查来阻止崩溃,但不知道怎么做
谁能建议合适的代码来处理这种情况以避免崩溃
谢谢
- (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;
}
}