0
我是新的int目標-C和我試圖創建一個時間計數器,但是當我啓動啓動方法,更新方法只有一次執行,然後我得到在控制檯中:創建時間計數器Objective-C
2010-12-11 14:11:45.080 StatusBarApp[10037:a0f] Break down: 0min 0hours 0days 0moths
Program received signal: 「EXC_BAD_ACCESS」.
sharedlibrary apply-load-rules all
我真的不明白問題所在。 這裏是我的代碼:
- (void)start:(id)sender {
recordDate = [NSDate date];
_timer = [NSTimer scheduledTimerWithTimeInterval:(1.0) target:self
selector:@selector(updateTime:) userInfo:nil repeats:YES];
[_timer fire];
}
- (void)stop:(id)sender {
[statusItem setTitle:@""];
[_timer invalidate];
[_timer release];
}
- (IBAction)updateTime:(id)sender {
// The time interval
// Get the system calendar
NSCalendar *sysCalendar = [NSCalendar currentCalendar];
// Create the NSDates
NSDate* date1 = [[NSDate alloc] init];
// Get conversion to months, days, hours, minutes
unsigned int flags = NSHourCalendarUnit | NSMinuteCalendarUnit | NSDayCalendarUnit | NSMonthCalendarUnit;
NSDateComponents* breakdownInfo = [sysCalendar components:flags fromDate:date1 toDate:recordDate options:0];
NSLog(@"Break down: %dmin %dhours %ddays %dmoths",[breakdownInfo minute], [breakdownInfo hour], [breakdownInfo day], [breakdownInfo month]);
[date1 release];
[statusItem setTitle:[NSString stringWithFormat:@" %dmin %dhours %ddays %dmoths",[breakdownInfo minute], [breakdownInfo hour], [breakdownInfo day], [breakdownInfo month]]];
}
它的工作原理! :) 非常感謝你! – aphex 2010-12-11 15:01:58