0
我有一个endGame视图,在用户完成游戏时加载。它以模态形式在游戏视图之上呈现。在viewDidLoad中,我正在调用一种方法来保存数据,例如分数以及他们玩过的特定游戏模式的数量。该方法被称为多次 - 大约每秒一次,但它是不规则的。不断调用方法,直到视图被解雇
结束游戏画面:
#import "endGameScreen.h"
#import "ViewController.h"
#import "GameData.h"
@implementation endGameScreen
- (void)viewDidLoad {
[super viewDidLoad];
}
- (void)awakeFromNib {
[self getAchievementData];
}
- (void)getAchievementData {
[RWGameData sharedGameData].timedPlayed++;
NSLog(@"Timed played: %ld", [RWGameData sharedGameData].timedPlayed);
}
- (void)writeAchievementforKey:(NSString *)achKey {
[data setObject:[NSNumber numberWithInteger:1] forKey:achKey];
[data writeToFile: path atomically:YES];
}
我加载了endGameScreen类是这样的: GameViewController.m
- (void)viewDidLoad {
if (self.gameMode == 1) {
self.gridSize = 3;
secondsLeft = 10;
[self countdownTimer];
}
}
-(void)countdownTimer {
secondsLeft = minutes = seconds = 0;
timer = [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(updateCounter:) userInfo:nil repeats:YES];
}
// Timer in the game going to zero
- (void)updateCounter:(NSTimer *)theTimer {
if (secondsLeft > 0){
secondsLeft -- ;
minutes = (secondsLeft % 3600)/60;
seconds = (secondsLeft %3600) % 60;
timePlayedLabel.text = [NSString stringWithFormat:@"%02d:%02d", minutes, seconds];
if (secondsLeft == 1) {
//Call endGame method
timer = [NSTimer scheduledTimerWithTimeInterval:1.0
target:self
selector:@selector(endGame)
userInfo:nil
repeats:NO];
}
}
else {
secondsLeft = 10;
}
}
- (void)endGame {
[timer invalidate];
[self saveScores];
//Segue in the storyboard
[self performSegueWithIdentifier:@"endGame" sender:self];
}
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if ([[segue identifier] isEqualToString:@"endGame"]) {
endGameScreen *vc = [segue destinationViewController];
if (self.gameMode == 1) {
vc.gameMode = 1;
}
else {
vc.gameMode = 2;
}
}
}
我得到,不断递增说的NSLog消息“模式一人出场:27分“,”模式一出场:28分“,”模式一出场:29分“等等。
嗨,你确定你不会在别的地方调用这个方法吗? – abarbier
请添加一些您的文件的代码这段代码没有描述您的问题? –
我已经添加了更多的endGameScreen类的代码,并展示了我在gameViewController中如何调用它。 –