How to fetch the currently selected row in the uipickerview when tapped Done ( having multiple pickers)
Solution 1
//Suppose you have created three picker views as firstPickerView, secondPickerView and ThirdPickerView
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
if(pickerView == firstPickerView)
{
NSString *strFirstPickerView = [yourarray objectAtIndex:row];
}
else if(pickerView == secondPickerView)
{
NSString *strSecondPickerView = [yourarray objectAtIndex:row];
}
else
{
NSString *strThirdPickerView = [yourarray objectAtIndex:row];
}
}
Solution 2
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
NSString *str = [yourarray objectAtIndex:row];
}
now str have a selected value. so you can use it when done button press.
Solution 3
selectedRowInComponent:
- Returns the index of the selected row in a given component.
- (NSInteger)selectedRowInComponent:(NSInteger)component
Parameters component A zero-indexed number identifying a component of the picker view. Return Value A zero-indexed number identifying the selected row, or -1 if no row is selected.
And to make a difference between different pickerViews add tag to each of the pickers:
self.pikcerView.tag = 1;
Hope this helps.
Comments
-
user198725878 about 2 years
I have got
UIPickerview
in my application working fine.I want to change the default selection behavior of the
UIPickerview
, i mean i have a done button in theUIToolbar
. The toolbar is added to theUIPickerview
.Whenever the user taps on the "Done" button, I want to consider the highlighted entry as selected. That means user can move up and down , when the user taps on the "Done" button, i want to consider the selection now
Please let me know , how can I fetch the currently selected row for the
UIPickerview
when tapped "Done" buttonNote: I have 3 pickers in my view ( i mean i want to have pickerview tag and pickerview selected row)