Hi
In my app I have next and previous week buttons, but also a UIDatePicker. So lets say I press the net week button, how can I adjust the day in the UIDatePicker to increase by 7 days? And visa versa for back 7 days.
Thanks!
Hi
In my app I have next and previous week buttons, but also a UIDatePicker. So lets say I press the net week button, how can I adjust the day in the UIDatePicker to increase by 7 days? And visa versa for back 7 days.
Thanks!
Use the dateByAddingTimeInterval:
method of the NSDate
class, and the setDate:animated:
method of the UIDatePicker
class, to adjust the picker's current date:
NSDate *currentDate = [datePicker date];
// Set the date 7 days earlier
NSDate *sevenDaysEarlier = [currentDate dateByAddingTimeInterval:-(60 * 60 * 24 * 7)];
[datePicker setDate:sevenDaysEarlier animated:YES];
// Set the date 7 days later
NSDate *sevenDaysLater = [currentDate dateByAddingTimeInterval:60 * 60 * 24 * 7];
[datePicker setDate:sevenDaysLater animated:YES];