开发者

NSTimer is not getting stopped

I am trying to stop the timer. My problem is when I try to stop the timer the value of timer is nil and it is not getting invalidated. if there any way to stop the timer except this ?

My code is like

timer is defined in header file - and also synthesized.

if([str_Message isEqualToString:ON] // if the command to start timer

{


 if(!timer) 

{

tmr_CallWebService = [[NSTimer scheduledTimerWithTimeInterval:Time_TracingInterval target:ClassTracing selector:@selector(startLocationTracing) userInfo:nil repeats:YES]retain];

}

//to stop timer

else if([str_Message isEqualToString:OFF])
{
if(timer)

{

[timer invalidate];
timer = nil;

}

Please help me out... t开发者_StackOverflow社区hanks in advance


I think you just need to replace tmr_CallWebService with timer.


[str_Message isEqualToString:ON] should be like this [str_Message isEqualToString:@"ON"]. similarly for the comparison with OFF. Use @"OFF".


If you've got a property declared for the timer, you should use it. For instance, if your timer is defined as @property (nonatomic, retain) NSTimer *myTimer; you should refer to it as self.myTimer and set it using that setter and invalidate it later using the accessor.

It looks like you're not setting tmr_CallWebService to your timer ivar at any place so you're just leaking and losing the reference.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜