try it out suppose you have two UIPickerView
like pickerview1
and pickerview2
then you can set the logic like bellow..
Note 1.:- If you used different 2 UIPickerView
then use bellow code..
- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
if (thePickerView == pickerview1) {
if ([yourTextfield.text integerValue] > row) {
int selectVal = [yourTextfield.text integerValue] - row ;
[pickerview2 selectRow:selectVal inComponent:0 animated:YES];
}
else{
int selectVal = row - [yourTextfield.text integerValue] ;
[pickerview2 selectRow:selectVal inComponent:0 animated:YES];
}
}
}
Here what you get just see here if you entered value in UITextField
7 and then select value 5 of pickerview1
then its row
number is 4
.
here when you minus that 4 from the 7 then what you get is 3 after you set or Select the row number is 3 of pickerview2
and its value is 2.
Note 2.:- If you used 1 UIPickerView
and 2 components then use bellow code..
- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
if (component == 0) {
if ([yourTextfield.text integerValue] > row) {
int selectVal = [yourTextfield.text integerValue] - row ;
[thePickerView selectRow:selectVal inComponent:1 animated:YES];
}
else{
int selectVal = row - [yourTextfield.text integerValue] ;
[thePickerView selectRow:selectVal inComponent:1 animated:YES];
}
}
}
So you got exact output which you want..
i hope you got it...
Enjoy the coding.. :)