Reputation:
I want to use UIPickerView
with 2 components, in which the second component value will be dependent on the first component value, like if in the first component Group 1 is selected then in the second component the group 1 values should be shown.
After selecting the values from both components value will be assigned to a UITextField
or UILabel
and the picker will be hidden.
(I have a main view in which I have added a subview to add the UIPickerView
).
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 2;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
if (component==0)
{
return [vGroup count];
}
else
{
return [vehiclePickerList count];
}
}
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
switch (component)
{
case 0:
return [vGroup objectAtIndex:row];
break;
case 1:
return [vehiclePickerList objectAtIndex:row];
break;
}
return nil;
}
Upvotes: 1
Views: 3750
Reputation: 920
Please provide some code what you have written. For component-related issues, use - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
.
Store corresponding values (which you want to show in component 2) of each row of component 1 in an array of dictionary, and load values from there.
Upvotes: 1