I don’t want to create NSTimer object. How do I invalidate timer? I want to invalidate timer in viewWillDisappear.
-(void) viewDidLoad
{
[super viewDidLoad];
[NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(onTimer:) userInfo:nil repeats:YES];
}
A
you have to hold on to the timer you create:
B
another option would be to invalidate the timer that is passed in the callback, but that won’t occur within
viewDidUnload:. therefore, it doesn’t quite apply in this scenario: