我試圖在文本字段中的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];
但文本框不會改變
你做了什麼來調試它? –
調試?沒什麼,我猜 – user2651455
爲什麼不呢?你不知道如何做基本的調試?你期望你的代碼每次都能第一次工作嗎? –