我已經啓動了一個計時器,在10秒後調用一個方法。計時器從didFinishLaunchingWithOptions開始。它工作正常,但我想在註銷時停止另一個UISubclass的計時器。我該怎麼做我的代碼是停止NSTimer從應用程序運行didFinishLaunchingWithOptions
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[NSThread sleepForTimeInterval:2.0];
[self.window addSubview:viewController.view];
[self setupTimer];
[self.window makeKeyAndVisible];
return YES;
}
-(void)setupTimer;
{
timer = [NSTimer timerWithTimeInterval:10
target:self
selector:@selector(triggerTimer:)
userInfo:nil
repeats:YES];
[[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
}
-(void)triggerTimer:(NSTimer*)timer;
{
NSLog(@"===============this method is call after every 10 second===========================");
Getlocation *object=[[Getlocation alloc] init];
[object updatelocation];
}
-(void)stopTimer:(NSTimer*)timer;
{
[timer invalidate];
timer=nil;
}
:感謝您的答覆,但我註銷登錄觀點出現後,這一次我不想執行的計時器任務,之後註銷。 –