发行NSTimer iPhone? [英] Releasing an NSTimer iPhone?

查看:57
本文介绍了发行NSTimer iPhone?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在.h中声明了一个NSTimer,在/m的viewDidLoad中声明了代码:

I have an NSTimer declared in my .h and in the viewDidLoad of the /m I have the code:

timer = [NSTimer scheduledTimerWithTimeInterval:kComplexTimer target:self selector:@selector (main) userInfo:nil repeats:YES];

我也有[定时器发布];在我的dealloc中.

I also have [timer release]; in my dealloc.

但是,当我退出视图并返回视图时,计时器实际上并没有释放,它的速度提高了一倍!我该如何解决&我在做什么错??

However when I exit the view and return to it, the timer has not in fact released, it has doubles in speed! How do I solve this & what am I doing wrong???

谢谢

推荐答案

很好的回答,但是很好地检查时间是否为零,以避免不必要的异常.

Nice Answer , but good to check whether the time is nil or not to avoid unwanted exception..

if( timer ! = nil )
{
  [timer invalidate];
  timer = nil;
}

谢谢...

这篇关于发行NSTimer iPhone?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆