Aquí hay soluciones simples para su problema.
Declaraciones
@interface ViewController : UIViewController
{
IBOutlet UILabel * result;
NSTimer * timer;
int currentTime;
}
- (void)populateLabelwithTime:(int)milliseconds;
-(IBAction)start;
-(IBAction)pause;
@end
Definición
- (void)viewDidLoad
{
[super viewDidLoad];
currentTime = 270000000; // Since 75 hours = 270000000 milli seconds
}
-(IBAction)start{
timer = [NSTimer scheduledTimerWithTimeInterval:.01 target:self selector:@selector(updateTimer:) userInfo:nil repeats:YES];
}
-(IBAction)pause{
[timer invalidate];
}
- (void)updateTimer:(NSTimer *)timer {
currentTime -= 10 ;
[self populateLabelwithTime:currentTime];
}
- (void)populateLabelwithTime:(int)milliseconds {
int seconds = milliseconds/1000;
int minutes = seconds/60;
int hours = minutes/60;
seconds -= minutes * 60;
minutes -= hours * 60;
NSString * result1 = [NSString stringWithFormat:@"%@%02dh:%02dm:%02ds:%02dms", (milliseconds<[email protected]"-":@""), hours, minutes, seconds,milliseconds%1000];
result.text = result1;
}
+1 para la explicación detallada. Seguid así. –
Hai funciona bien con algunos cambios ... tengo la vista de desplazamiento en la que estoy mostrando la hora ... Si arrastro la vista de desplazamiento la hora no está calculando (en el fondo también) ... lo que tengo que hacer. ..? – SriKanth
Agregue este código para habilitar el temporizador durante el desplazamiento ........................................ .......................................... - (IBAction) start { timer = [NSTimer scheduledTimerWithTimeInterval: .01 target: selector automático: @selector (updateTimer :) userInfo: nil repeat: YES]; [[NSRunLoop currentRunLoop] addTimer: timer forMode: NSRunLoopCommonModes]; } –