2

我正在构建一种模拟,“滴答声”之间的间隔越来越小:

- (void) simulationTick {
    if (self.currentTick >= kNumberOfSimulationTicks)
        return; // recursion anchor

    // ... do stuff ...

    self.currentTick = self.currentTick + 1;
    [self performSelector:@selector(simulationTick) withObject:nil
               afterDelay:2.5 * pow(0.95,(double)self.currentTick)]; // acceleration
}

离开模拟屏幕时,我想停止模拟,所以我这样做

[NSObject cancelPreviousPerformRequestsWithTarget:self]

我第一次尝试使用

[[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget:self]

……但这没有用。

为什么不?

显然,还有许多 其他人有同样的问题和相同的解决方案。但我无处可寻。两者有什么区别?

4

0 回答 0