Search code examples
iosuipickerviewiphone-sdk-3.0

How to select row from UIPickerView iPhone?


I want to select value from uipickerview and display it in textfield and also hide after selecting. I tried following but it scrolls once and display last value of scrolling in textfield and hide textfield. I don't want it i want user to scroll multiple time and selecting row.

- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {

    self.txtfield.text = [arrNum objectAtIndex:row];
    self.numPicker.hidden = TRUE;
}

Solution

  • Put the date picker inside a view with a 'Done' button and present that view modally. Set the value of text filed in the action for the Done button instead of didSelectRow delegate method. Then dismiss the modal view.

    In addition you can add a cancel button to the view to directly dismiss it.