我正在尝试在文本字段中的 datePicker 中显示时间。我已经走到这一步了
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(112, 88, 97, 30)];
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
[self.view addSubview:textField];
UIDatePicker *datePicker = [[UIDatePicker alloc] init];
datePicker.datePickerMode = UIDatePickerModeDate;
[datePicker addTarget:self action:@selector(datePickerValueChanged:) forControlEvents:UIControlEventValueChanged];
datePicker.timeZone = [NSTimeZone defaultTimeZone];
datePicker.minuteInterval = 5;
datePicker.datePickerMode = UIDatePickerModeTime;
[textField setInputView:datePicker];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle: NSDateFormatterShortStyle];
textField.text = [dateFormatter stringFromDate:datePicker.date];
但是文本字段不会改变