2011-10-22 57 views
0

在下面的代碼時將創建一個碰撞,如果我的同時旋轉2個組件偶爾取決於選擇哪些陣列,該值將是出界Uipicker碰撞紡絲2個部件simultaneuosly

我需要一些條件檢查其將停止崩潰,但不知道什麼如何

任何人都可以建議適當的代碼將處理條件,避免碰撞

感謝

- (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; 
     } 
} 

回答

0

問題可能在titleForRow方法或numberOfRows方法。你必須確保你沒有超出所討論陣列的範圍。

+0

好的,我如何確保我不會出界? – superllanboy

+0

@superllanboy NSArrays有一個count方法,所以你總是可以做'if(indexIWant

+0

對不起,我沒有足夠的經驗去理解如何將這些語句合併到條件處理中爲上面的選擇器設計 – superllanboy