我有一個基於核心數據的應用程序,我正在使用它,它使用EditingViewController來控制許多不同的UI元素,這些元素從用戶處獲得輸入,這些輸入描述隨後存儲在我的應用程序中的對象的屬性。 EditingViewController.xib文件具有諸如datePicker,textField,numberSlider和我的問題來自UIPickerView的所有元素,這些元素都使用.hidden = YES/NO;
表達式在一個視圖中進行控制。我的問題是我需要在兩個單獨的屏幕中填充一個UIPickerView,它需要兩個不同的NSMutableArray來源。在我的viewDidLoad方法中設置我的第一個的NSMutableArray:UIPickerView與2個NSMutableArrays?
listOfItems = [[NSMutableArray alloc] init];
[listOfItems addObject:@"Greenland"];
[listOfItems addObject:@"Switzerland"];
[listOfItems addObject:@"Norway"];
[listOfItems addObject:@"New Zealand"];
[listOfItems addObject:@"Greece"];
[listOfItems addObject:@"Rome"];
[listOfItems addObject:@"Ireland"];
在這之後,我填充我UIPickerView *選擇器使用此代碼:
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)picker;
{
return 1;
}
- (void)pickerView:(UIPickerView *)picker didSelectRow:(NSInteger)row inComponent: (NSInteger)component
{
label.text= [listOfItems objectAtIndex:row];// The label is simply setup to show where the picker selector is at
}
- (NSInteger)pickerView:(UIPickerView *)picker numberOfRowsInComponent:(NSInteger)component;
{
return 8;//[listOfItems count];
}
- (NSString *)pickerView:(UIPickerView *)picker titleForRow:(NSInteger)row forComponent: (NSInteger)component;
{
return [listOfItems objectAtIndex:row];
}
這對第一屬性和陣列工作正常。那麼之後,當選擇不同的uitableviewcell時,選擇器被隱藏picker.hidden = YES;
,我需要另一個選擇器,picker2顯示不同的信息數組。但是當我嘗試並複製過程時,通過設置一個全新的選擇器,將其稱爲picker2,並試圖用我在第一個旁邊創建的另一個NSMutableArray填充它(再次,因爲在我的EditingViewController中它全部是隻是根據視圖調用不同的UI元素)我不能讓picker2填充新的數組。我不知道如何設置它,以便我的兩個不同的陣列可以填充。我需要兩個選擇器視圖嗎?它可以只用一個來完成嗎?在- (NSString *)pickerView:(UIPickerView *)picker titleForRow:(NSInteger)row forComponent: (NSInteger)component;
方法中使兩個數組單獨可見的正確語法是什麼?希望有人能幫我解決這個問題,提前謝謝!
哇,謝謝!那太完美了! – Steve 2010-01-19 11:07:09