Reputation: 23
Im working with a double (two-component) picker view. When I run it shows me the double picker view, but the same information in both component's rows.
Here is the code hope you can help me.
I want to show in the first component the array1 and in the second component the array2.
- (void)viewDidLoad {
NSArray *FirstArray1 = [[NSArray alloc] initWithObjects:
@"White",@"Whole Wheat",@"Rye",@"Sourdough",@"Seven Grain", nil];
self.Array1 = FirstArray1;
NSArray *FirstArray2 = [[NSArray alloc] initWithObjects:
@"Turkey",@"Peanut Butter",@"Tuna Salad",@"Chicken Salad",@"Roast Beef",
@"Vegemite",nil];
self.Array2 = FirstArray2;
[super viewDidLoad];
}
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 2;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView
numberOfRowsInComponent:(NSInteger)component
{
return[self.Array1 count];
return[self.Array2 count];
}
-(NSString *)pickerView:(UIPickerView *)pickerView
titleForRow:(NSInteger)row
forComponent:(NSInteger)component
{
return [self.Array1 objectAtIndex:row];
return [self.Array2 objectAtIndex:row];
}
Upvotes: 2
Views: 1173
Reputation: 5100
This is how I like to manage things...
let pickerData = [["column1_1","column1_2","column1_3","column1_4"],
["column2_1","column2_2","column2_3","column2_4"]]
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return pickerData[component].count
}
The component number references the array, nice and simple.
Upvotes: 1
Reputation: 5038
-(NSInteger)pickerView:(UIPickerView *)pickerView
numberOfRowsInComponent:(NSInteger)component
{
if (component == 0) {
return[self.Array1 count];
} else if (component == 1) {
return[self.Array2 count];
}
return 0;
}
Upvotes: 2