相关疑难解决方法(0)

如何知道何时使'NSTimer`无效

这是我的问题:

我有一个模型类,其中有一个NSTimer我希望Timer在模型对象的整个生命周期内运行.初始化很简单:我在init方法中只有以下代码行:

self.maintainConnectionTimer = 
             [NSTimer scheduledTimerWithTimeInterval:1 
                                              target:self 
                                            selector:@selector(maintainConnection) 
                                            userInfo:nil 
                                             repeats:YES];
Run Code Online (Sandbox Code Playgroud)

但是,我的问题是,当模型从内存中释放时,如何使此计时器无效? 现在,这通常很容易,但据我所知,当您安排NSTimer操作系统维护一个指向Timer对象的强指针时.

我应该怎么处理这个?是否有一种方法在模型从内存中释放之前被调用?

iphone objective-c nstimer ios automatic-ref-counting

6
推荐指数
1
解决办法
2727
查看次数