我的NSTimer(startTimer所)工作正常。它运行选定的方法(runTimer),但是我放置在(runTimer)中的任何代码都不会增加。例如,如果我像下面那样运行代码,它会打印出5次,但不会增加x。任何想法 - 感谢的NSTimer火灾而不是递增(写只允许进行控制台)
- (void)startTimer {
self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(runTimer:) userInfo:nil repeats:YES];
[[NSRunLoop mainRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:5]];
}
- (void)runTimer:(NSTimer *)aTimer {
int x;
x++;
NSLog(@"int x = %i",x);
}
谢谢大家 - 我现在明白了。我刚刚创建了一个ivar int(int num)集合属性,并使用self.num + = 1重新运行代码,并且所有工作都正常。 – pete 2012-01-27 17:11:14
很高兴听到它。请确保您通过点击答案左侧的复选标记来接受最能帮助您的答案。这样做可以让未来的回答者获得更多的帮助。 – 2012-01-27 17:38:43