Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/43.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 释放NSObject并停止所有方法调用_Iphone - Fatal编程技术网

Iphone 释放NSObject并停止所有方法调用

Iphone 释放NSObject并停止所有方法调用,iphone,Iphone,因此,我的菜单使用以下代码调用游戏: game = [[Game alloc] init]; [self presentModalViewController:memoryTest animated:FALSE]; 然后出现一个UIViewController,并显示倒计时。在倒计时期间,玩家可以返回菜单。然而,当我尝试这一点时,倒计时一直在运行,最终游戏开始,即使UIViewController已被解除,因此UIView已在backToMenu方法中消失 [self.parentViewCo

因此,我的菜单使用以下代码调用游戏:

game = [[Game alloc] init];
[self presentModalViewController:memoryTest animated:FALSE];
然后出现一个UIViewController,并显示倒计时。在倒计时期间,玩家可以返回菜单。然而,当我尝试这一点时,倒计时一直在运行,最终游戏开始,即使UIViewController已被解除,因此UIView已在backToMenu方法中消失

[self.parentViewController dismissModalViewControllerAnimated:FALSE];
我试着在菜单的viewdide方法中释放游戏对象,但没有成功。我想有一个quit BOOL值,这样倒计时可以检查玩家是否退出游戏,但必须有更好的方法来释放对象并停止其中的所有方法调用

谢谢你帮我

倒计时方法:

- (void)countDown {

    SoundEffect *sound = [[SoundEffect alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"tick" ofType: @"wav"]];
    [sound playAndRelease];

    if(self.countDownStep > 0) {
        feedback.image = [UIImage imageNamed:[NSString stringWithFormat:@"countdown%d.png",self.countDownStep]];
        feedback.hidden = FALSE;

        [self performSelector:@selector(countDown) withObject:nil afterDelay:0.8];
    }

    else {
        [self displayMessage:self.startMessage];
        [self.game performSelector:@selector(start) withObject:nil afterDelay:0.8];
        [self performSelector:@selector(hide) withObject:nil afterDelay:0.8];
    }

    self.countDownStep--;

}

你如何处理倒计时?似乎您希望在您提到的UIViewController的ViewWillEnglishe方法中显式地取消倒计时。

我假设您将使用类似NSTimer的东西。事实上,这可能仍然不是一个坏主意。NSTimer可以处理每0.8秒重新运行倒计时方法的问题。如果将该值减为0,则您的倒计时已过期。如果视图消失,请在ViewWillEnglish中使计时器无效。

在viewcontroller的ViewWillEnglish中,检查计时器是否正在运行。如果是,那就让它失效


[timerObject invalidate]将停止计时器

Cocoa使用YES/NO而不是False/True。我想你的意思是停止它?除了使用变量比较,您将如何做到这一点?