UIPickerView didSelectRow function not working for default value

Discussion in 'iOS Programming' started by ashwinr87, Jan 15, 2012.

  1. ashwinr87 macrumors member

    Mar 9, 2011

    In the UIPickerView I use in my application, I set the default value by using this -
    [pickerView selectRow:0 inComponent:0 animated:NO];
    and I use the
    - (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
    function to get the value of whatever number I pick from the UIPicker view.

    The problem I am facing is that if I want to select the default item shown on the UIPickerView, untill I roll the wheel and come back to the default value, I am unable to select the default value. The `didSelectRow` function does not get called when I click on the default value.

    Would someone be able to help me out with this problem?
  2. MattInOz macrumors 68030


    Jan 19, 2006
    You might need to look how you are presenting the picker view.

    The picker doesn't have a cancel method of it's own it relies on the on the view presenting to handle that. It just reports any and all changes until the view gets closed off by it's superview (say a UIPopover). At that point you can take the selection to be the default or a new setting and change the data.

    The assumption seems to be that if the user cancels the superview then they are either happy with the value or opened the wrong control and don't care.

    You might need to make your controller a delegate of the presenting view as well as the picker so that it gets told about the cancelling of the view.

Share This Page