UIDatePicker date picking problem
how to show start date and end date in date picker and select them to perform some event in iPhone
NSCalendar *calendar = [NSCalendar开发者_如何学编程 autoupdatingCurrentCalendar];
// Get the current date
NSDate *pickerDate = [self.datePicker date];
NSDateComponents *dateComponents = [calendar components:( NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit )
fromDate:pickerDate];
NSDateComponents *timeComponents = [calendar components:( NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit )
fromDate:pickerDate];
// Set up the fire time
NSDateComponents *dateComps = [[NSDateComponents alloc] init];
[dateComps setDay:[dateComponents day]];
[dateComps setMonth:[dateComponents month]];
[dateComps setYear:[dateComponents year]];
[dateComps setHour:[timeComponents hour]];
// Notification will fire in one minute
[dateComps setMinute:[timeComponents minute]];
[dateComps setSecond:[timeComponents second]];
NSDate *itemDate = [calendar dateFromComponents:dateComps];
[dateComps release];
You could create a UITableView with two rows, one for the start and one for the end date. Then in the didSelectRowAtIndexPath you set the datePicker.tag to the indexPath.row. When reveicing UIControlEventValueChanged you can simpy get the NSDate from the UIDatePicker and assign it to your variable.
精彩评论