日付ピッカー モードが に設定されている場合は、countDownDuration
プロパティを使用する必要があります。UIDatePicker
UIDatePickerModeCountDownTimer
カウントダウン期間は秒単位であるため、次のように NSDate から計算できます (テストするにはviewDidLoad
、 anyの にドロップするだけですUIViewController
)。
// Create a new date with the current time
NSDate *date = [NSDate new];
// Split up the date components
NSDateComponents *time = [[NSCalendar currentCalendar]
components:NSHourCalendarUnit | NSMinuteCalendarUnit
fromDate:date];
NSInteger seconds = ([time hour] * 60 * 60) + ([time minute] * 60);
UIDatePicker *picker = [UIDatePicker new];
[picker setDatePickerMode:UIDatePickerModeCountDownTimer];
[picker setCountDownDuration:seconds];
[[self view] addSubview:picker];
したがって、現在の時刻が 17:28 の場合、UIDatePicker
は「17 時間 28 分」と表示します。NSDateをDBから取得したものに置き換えるだけで、ソートされるはずです:)