0
所以我得到了我的用戶界面選擇器,但它顯示的是每個用戶界面選擇器的相同數據,但我希望它能在一個用戶界面中顯示鬍子陣列和另一個顏色。目前在映像中顯示的是將相同的數據分配給每個陣列。在同一視圖控制器中的兩個UI採集器目標C?
- (void)viewDidLoad
{
[super viewDidLoad];
_colourSourceArray = [[NSArray alloc] initWithObjects:@"No Frame",@"Red", @"Green", @"Blue", @"Black",@"Yellow", nil ];
_MustacheArray = [[NSArray alloc]initWithObjects:@"None",@"Pencil",@"The Professor",@"The Regent",@"Hipster",@"Super Mario", nil];
[_picker selectRow:0 inComponent:0 animated:YES];
[_notcolourpicker selectRow:1 inComponent:0 animated:YES];
_picker.tag=0;
_notcolourpicker.tag=1;
}
- (NSInteger)numberOfComponentsInPickerView: (UIPickerView *)pickerView
{
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
switch (component) {
case 0:
return _colourSourceArray.count;
break;
case 1:
return _MustacheArray.count;
default:
break;
}
return 0;
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
switch (component) {
case 0:
return [_colourSourceArray objectAtIndex:row];
break;
case 1:
return [_MustacheArray objectAtIndex:row];
default:
break;
}
return 0;
}
-(IBAction)returnToExportSettingsVC:(UIStoryboardSegue *)segue
{
// Nothing needed here.
}
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
if (component == 0) {
NSLog(@"First");
NSString *s = _colourSourceArray[row];
_selectedcolour = s;
NSLog(_selectedcolour);
}
else
if(component == 1){
NSLog(@"Second");
NSString *d = _MustacheArray[row];
_selectedmustache=d;
NSLog(_selectedmustache);
}
/// Used if you wist to assign the selected row to a label to show a users selection.
//_label.text= [_MustacheArray objectAtIndex:[mostachepicker selectedRowInComponent:1]];
}
只需在故事板中的選取器視圖中添加一個'tag',然後從數據源返回數據時,通過執行'if picker.tag == 1 {...} else檢查哪個選擇器正在請求數據if picker.tag == 2 {...}' – sbarow