I have the following code that is designed to change the var class, called today, forward or backward, for one day. It will work once, but after that it will work. He will do the same, regardless of whether I press the left button or the right button. What am I doing wrong?
var today is the var class, initiated as .. today = [NSDate date]
Here is the method that crashes:
(IBAction)changeDateByOne:(id)sender{
NSDate *newDay;
NSDate *currentDay = today;
NSTimeInterval secondsPerDay = 24 * 60 * 60;
if(sender == leftButton){
newDay = [currentDay addTimeInterval:-secondsPerDay];
}else if(sender == rightButton) {
newDay = [currentDay addTimeInterval: secondsPerDay];
}
today = newDay;
}
source
share