2012-01-12 8 views
0

私はカウントダウンを含むアプリを書いています。カウントダウンはラベルに表示されますが、ラベルを最も効率的に更新するかどうかはわかりません。私は1秒間隔のタイマーを使用しています。より少ないリソースを消費する方法はありますか?また、これは古いデバイスでクラッシュしますか?最も効果的なライブカウントダウンの方法

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
//Create Calendar for NSDates 
gregorian = [[NSCalendar alloc]initWithCalendarIdentifier:NSGregorianCalendar]; 
[gregorian setTimeZone:[NSTimeZone timeZoneWithName:@"EST"]]; 

//Create NSDate lunchTime based on Now 
now = [NSDate date]; 
NSDateComponents *compsOfNow = [gregorian components:(NSWeekdayCalendarUnit |NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit |NSYearCalendarUnit|NSMonthCalendarUnit|NSEraCalendarUnit)fromDate:now]; 
[compsOfNow setHour:12]; 
[compsOfNow setMinute:50]; 
lunchTime = [gregorian dateFromComponents:compsOfNow]; 

//Create timer and set text 
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timerTicked:) userInfo:nil repeats:YES]; 
lunchCountdownLabel.text = [NSString stringWithFormat:@"%i:%i:%i", difference.hour, difference.minute, difference.second]; 

} 

- (void)timerTicked:(NSTimer*)timer { 
now = [NSDate date]; 
difference = [gregorian components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit|NSHourCalendarUnit|NSMinuteCalendarUnit|NSSecondCalendarUnit fromDate:now toDate:lunchTime options:0]; 
lunchCountdownLabel.text = [NSString stringWithFormat:@"%i:%i:%i", difference.hour, difference.minute, difference.second]; 
NSLog(@"Timer Ticked"); 
あなたの入力が高く評価され

おかげで、

HBhargava

答えて

0

これは私には罰金だが...ちょうどあなたがそれで行われたら、タイマーを無効にすることを忘れないでください。(これはあなたは現在行っていません)