0
我想通過一個選定的時間與UIDatePicker來更改標籤的文本,但是當我更新它時,它總是以0:01結束。UIDatePickerView日期始終是加載0:01
我已經嘗試在新項目中使用自己的代碼,它的功能,所以這是關於我的其他功能。
- (void)viewDidLoad {
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"HH:mm"];
pickerLabel.text = [NSString stringWithFormat:@"%@",
[df stringFromDate:[NSDate date]]];
[self.view addSubview:pickerLabel];
[self.view addSubview:picker];
}
當完成按鈕被點擊時,它會更新標籤值並將datepicker的uiview動畫出來。
- (IBAction)savePalette:(id)sender {
[UIView beginAnimations:@"animateView" context:nil];
[UIView setAnimationDuration:0.5];
CGRect viewFrame = [animatedView frame];
viewFrame.origin.y = 480;
animatedView.frame = viewFrame;
animatedView.alpha = 1.0;
[self.view addSubview:animatedView];
[UIView commitAnimations];
NSLog(@"saving and close");
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"HH:mm"];
pickerLabel.text = [NSString stringWithFormat:@"%@", [df stringFromDate:picker.date]];
NSLog([NSString stringWithFormat:@"%@",[df stringFromDate:picker.date]]);
}
任何幫助表示讚賞,謝謝!我認爲問題在於從選取器中取出的日期不會被轉移。
謝謝!
我想我不知道如何從完成按鈕中選擇日期。理想情況下,完成按鈕關閉調色板並從日期選取器中提取日期。你的第二個代碼是selectedTime:方法嗎? –
沒有第二位代碼純粹是爲了datepicker初始化。方法selectedTime用於選擇日期選擇器日期。每次datePicker收到一個滾動並且在一個日期中靜止時,都會調用此方法。因此,使用完成按鈕,您必須強制調用selectedTime方法(在選定的時間方法內,您可以通過datePicker.date獲取日期)。 – Xcoder
UIBarButtonItem * doneButton = [[UIBarButtonItem alloc] initWithTitle:@「Done」 style:UIBarButtonItemStyleBordered target:self action:@selector(selectedTime :)]; – Xcoder