в .ч
UIDatePicker *datePicker;
NSDate *date;
UIToolbar *keyboardToolbar;
в ViewDidLoad:
if (keyboardToolbar == nil) {
keyboardToolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 44)];
[keyboardToolbar setBarStyle:UIBarStyleBlackTranslucent];
UIBarButtonItem *extraSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
UIBarButtonItem *accept = [[UIBarButtonItem alloc] initWithTitle:@"Accept" style:UIBarButtonItemStyleDone target:self action:@selector(closeKeyboard:)];
[keyboardToolbar setItems:[[NSArray alloc] initWithObjects: extraSpace, accept, nil]];
}
self.txtDate.inputAccessoryView = keyboardToolbar;
datePicker = [[UIDatePicker alloc] init];
datePicker.datePickerMode = UIDatePickerModeDate;
[datePicker addTarget:self action:@selector(datePickerValueChanged:) forControlEvents:UIControlEventValueChanged];
self.txtDate.inputView = datePicker;
- (void)datePickerValueChanged:(id)sender{
date = datePicker.date;
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"dd/MM/YYYY"];
[self.txtDate setText:[df stringFromDate:date]];
}
в раскадровке добавить в txtDate -> EditingDidEnd
- (IBAction)establishHour:(id)sender{
hour = hourPicker.date;
NSDateFormatter *hf = [[NSDateFormatter alloc] init];
[hf setDateFormat:@"HH:MM"];
[self.txtHour setText:[hf stringFromDate:hour]];
}
Устанавливает клавиатуру в качестве DatePicker и создает панель инструментов с кнопкой для подтверждения выбора.