在后台运行时间间隔计算

我有一个基本上是NSTimeInterval
NSTimeInterval interval = [date1 timeIntervalSinceDate: [NSDate date]];
当我在视图X中时,我希望这个计算总是在后台运行,所以我可以在UILabel中显示倒计时器...我该怎么做?它就像在iphone app的groupon中一样,但它没有在秒的细节中显示它     
已邀请:
您可以使用NSTimer来获取以设定的时间间隔调用的方法(但是这都是在主线程上执行的,而不是在后台线程上执行的):
- (void)setupTimer {
    //Start a timer to call update updateInterval: every 1 second
    self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0
                                               target:self
                                               selector:@selector(updateInterval:)
                                             userInfo:nil
                                              repeats:YES];
}

- (void)updateInterval:(NSTimer *)timer {
    NSTimeInterval interval = [date1 timeIntervaleSinceDate:[NSDate date]];
    //Do other things like updating the label
}
    

要回复问题请先登录注册