Reputation: 315
I am making a game and after player wins I am setting another view controller as root view controller.
finishViewController*fvc=[[finishViewController alloc] initFor:0];
[UIApplication sharedApplication].delegate.window.rootViewController=fvc;
But NSTimer
made on that view controller keeps working and when I run that view controller again it works strange and bugged. Is there any way to completely dealloc that viewController when i am setting another as root view controller? This may be easy question sorry, kinda new to Objective-c
Upvotes: 0
Views: 229
Reputation: 18488
It depends on what you want, if you will not be using that View Controller anymore it is safe to deallocate it, still even if you deallocate that controller that NSTimer will keep running unless you send a [myNSTimer invalidate] message to it and then dealloate with [myNSTimer release], (note you only need to release if your timer was retained).... to it in your ViewController's dealloc method.
If you are using ARC all you need is:
- (void)dealloc {
[myNSTimer invalidate];
}
Again this is only if you will not use that ViewController again and wish to release it. If you do not want to release it, you can simply do this before setting your new rootViewController (which I don't think you should do as using a Navigation Controller or modal view would be better):
[myNSTimer invalidate];
This will stop the NSTimer.
Upvotes: 1