I have two columns pickerView. In first column i have units like km, feet. I want to set different values for both like km 1,2,3 and for feet 100, 2000, 300. Now I did following code. I declare two arrays unitArray and distanceArray in viewDidLoad method.
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
return 2;
}
-(NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
if (component == UNIT)
return [unitArray objectAtIndex:row];
else
return [distanceArray objectAtIndex:row];
}
- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
distanceRow = [distancePicker selectedRowInComponent:DISTANCE];
unitRow = [distancePicker selectedRowInComponent:UNIT];
dist = [distanceArray objectAtIndex:distanceRow];
unit = [unitArray objectAtIndex:unitRow];
txtIBOutletDistance.text =[NSString stringWithFormat:@"%@ %@",dist,unit];
}
After doing this code i am showing same values for both km and feet i.e km and feet in one column and 1,2,3 in second column. I want after selecting km values should be 1,2,3 and for feet selection values should be 100,200,300. If any one knows how to do it please help me. I will appreciate him/her.
You should change the value of distanceArray in pickerView:didSelectRow:inComponent according to the selected UNIT as below: