2012-12-08 25 views
1

如何针对NSTimer每秒降低分数(例如,问题1:有10分)? 我已经减少到这一点,直到15秒。相对于NSTimer降低分数

在此先感谢。

+0

没错,米尝试。其实我不知道如何保存NSTimer的每一秒钟,特别是变量 – Abha

+1

然后创建一个计时器,每秒调用一次方法。让该方法将你的分数减1(假设时间现在为零,则停止该计时器)。 – Rob

+0

这意味着你想保存每个减少第二个商店或什么..? –

回答

2

将这个界面中的任何

@interface ViewController : UIViewController { 
    NSTimer *timer; 
    int seconds; 
} 
@property(nonatomic, strong) NSTimer *timer; 

这在您的实现在你需要它

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    self.timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timerTick:) userInfo:nil repeats:YES]; 
    seconds = 1;  
} 

- (void)timerTick:(id)sender{ 
    NSLog(@"%d",seconds); 
    if (seconds == 15) { 
     [self.timer invalidate]; 
    } 
    seconds++; 
}