He creado una aplicación de prueba con temporizador antes de implementarlo en mi proyecto. Fue la primera vez que uso el temporizador. Pero el problema es cuando implementé el temporizador usando [NSTimer timerWithTimeInterval: target: selector: userInfo: repeats: ];
, no está funcionando. Aquí está mi código, Interfaz:NSTimer timerWithTimeInterval: no funciona
@interface uialertViewController : UIViewController
{
NSTimer *timer;
}
-(void)displayAlert;
-(void)hideandview;
@end
Implementación:
@implementation uialertViewController
- (void)viewDidLoad {
[self displayAlert];
[super viewDidLoad];
}
-(void)displayAlert{
timer = [NSTimer timerWithTimeInterval:1 target:self selector:@selector(hideandview) userInfo:nil repeats:NO];
alert = [[UIAlertView alloc] initWithTitle:@"testing" message:@"hi hi hi" delegate:nil cancelButtonTitle:@"continue" otherButtonTitles:nil];
[alert show];
[alert release];
alert = nil;
}
-(void)hideandview{
NSLog(@"triggered");
[alert dismissWithClickedButtonIndex:0 animated:YES];
[alert release];
[self displayAlert];
}
@end
Luego cambié[NSTimer timerWithTimeInterval: target: selector: userInfo: repeats: ];
con[NSTimer scheduledTimerWithTimeInterval: target: selector:userInfo: repeats: ];
, se está trabajando. ¿Cuál fue el problema con timerWithTimeInterval:
? ¿Estoy malinterpretando algo en mi primera implementación? Gracias por adelantado.
timerWithTimeInterval crea el temporizador pero no lo inicia y programa ... lo hace. Creo que esa es la única diferencia – rooster117
@ rooster117: entonces tengo que llamar a los temporizadores método de disparo, ¿estoy en lo correcto? –
Sí o simplemente llame a scheduledTimerWithTimeInterval cuando desee iniciarlo. De cualquier manera – rooster117