Search code examples
iphoneiosuipickerview

How to fetch the currently selected row in the uipickerview when tapped Done ( having multiple pickers)


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 the UIToolbar. The toolbar is added to the UIPickerview.

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" button

Note: I have 3 pickers in my view ( i mean i want to have pickerview tag and pickerview selected row)


Solution

  • //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];
        }
    }