Je suis nouveau dans l'objectif-c et j'essaye de créer un compteur de temps, mais quand je commence la méthode de démarrage, la méthode de mise à jour est seulement une fois exécutée et puis je reçois dans la console:Créer compteur de temps avec 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
Je ne comprends vraiment pas où est le problème. Voici mon code:
- (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]]];
}
Cela fonctionne! :) Merci beaucoup! – aphex