時間を表示する UIButton があり、この時間は UIButton の titleLabel プロパティに表示されます。この時間を変更するには、ボタンをクリックして、日付ピッカーを呼び出すこのメソッドを呼び出します。
- (IBAction)slidePickerIn:(id)sender {
// Ok button to dismiss picker
[self.view bringSubviewToFront:self.datePickerOK];
// Bring picker to front
[self.view bringSubviewToFront:self.datePicker];
// animate entrance of picker and fade in of dismiss button
[UIView animateWithDuration:.5 animations:^{
[self.datePicker setFrame:pickerIn];
self.datePickerOK.alpha = 1;
}];
}
非表示ボタンをクリックすると、このメソッドが呼び出されます。日付ピッカーと閉じるボタンを取り除き、時間を表示するボタンのタイトルを更新します。
- (IBAction)slideDatePickerOut {
[UIView animateWithDuration:.5 animations:^{
self.datePickerOK.alpha = 0;
[self.datePicker setFrame:pickerOut];
}];
// Set time correctly
NSDate *wake = self.datePicker.date;
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"hh:mm a"];
self.wakeUpTime.titleLabel.text = [NSString stringWithFormat:@"%@", [df stringFromDate:wake]];
self.wakeUpTime.date = wake;
}
画面には、slidePickerIn を呼び出す別のボタンがあり、時間を変更できます。
問題: この別のボタンをクリックして表示される日付を変更すると、すべて正常に動作します。ただし、時間を示すタイトルを含むボタン自体をクリックすると、日付ピッカーが表示されている間、日付は午前 00:00 (デフォルト値) になります。日付ピッカーを閉じると、時刻が正しく更新されます。しかし、先ほど言ったように、他のボタンを使用しても、ピッカーが表示されている間の時間の値は変わりません。なぜこれができるのか、私には本当にわかりません。どんな助けでも大歓迎です。