我有下面的代码,这是为了改变一个名为“今天”的类var前进或后退一天。它会工作一次,但之后它崩溃。无论按下左键还是右键,它都会执行相同操作。我究竟做错了什么?NSDate问题
今天的变种是发起的。如今= [NSDate的日期]
这里一类变种是,崩溃的方法:
(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;
}
而不是`today = [[NSDate date] retain];`,最好是:`today = [[NSDate alloc] init];```````````````` – user102008 2011-04-19 21:52:00