Good afternoon, there is a question which I can not solve.

I need to select a value in PickerView and I need it to be displayed in Label when selected. How to do it? Those. I spin the picker. It automatically displays the selected option in the Label, then I just click "OK" and it remains there and the picker is hidden.

PS I know how to take a DatePicker , but DatePicker don’t get anything simple = (


There is a method

 - (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component { NSLog(@"Selected Color: %@. Index of selected color: %i", [array objectAtIndex:row], row); } 

That's all

    1 answer 1

    store the picker as an outlet or bind a function, for example:

     - (IBAction)valuePickerChanged:(id)sender { [self validateDatePicker]; } - (void)validateDatePicker { //may becheck data NSDateFormatter *df = [[NSDateFormatter alloc] init]; [df setDateStyle:NSDateFormatterMediumStyle]; [df setTimeStyle:NSDateFormatterShortStyle]; [self.yourLabel setTitle:[NSString stringWithFormat:@"%@", [df stringFromDate:self.datePicker.date] ]]; }