2012-01-17 10 views
1

私は、ユーザーの生年月日から後日までカウントダウンしているUILabelを更新しようとしています。私は彼らがそれをカウントダウン見ることができるようにラベルを更新しようとしているが、それを働かせるように見えない。アドバイスをいただければ幸いです!タイマーでUILabelを更新しない

私はタイマーを作るのはここです:私は実際にカウントダウン情報を取得する場所

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view from its nib. 
    [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timeFormatted:) userInfo:nil repeats:NO]; 
} 

、ここでは...

- (NSString *)timeFormatted:(int)totalSeconds 
{  
    NSTimeInterval theTimeInterval = [self numberOfSecondsToLive]; 

    NSCalendar *sysCalendar = [NSCalendar currentCalendar]; 

    NSDate *date1 = [[NSDate alloc] init]; 
    NSDate *date2 = [[NSDate alloc] initWithTimeInterval:theTimeInterval sinceDate:date1]; 

    unsigned int unitFlags = NSHourCalendarUnit | NSMinuteCalendarUnit | NSDayCalendarUnit | NSMonthCalendarUnit | NSYearCalendarUnit | NSSecondCalendarUnit; 

    NSDateComponents *conversionInfo = [sysCalendar components:unitFlags fromDate:date1 toDate:date2 options:0]; 

    _numberofSeconds.text = [NSString stringWithFormat:@" %dyears:%dMonths:%ddays:%dhour:%dminutes:%dseconds",[conversionInfo year],[conversionInfo month], [conversionInfo day], [conversionInfo hour], [conversionInfo minute], [conversionInfo second]]; 

    [date1 release]; 
    [date2 release]; 
} 

は何が起こることは、それが正しいカウントダウン情報を表示しないことですしかし、それは更新されません。

ありがとうございます!

答えて

5

repeats:NOでタイマーを開始しました。repeats:YESにタイマーを繰り返してもらいたいとします。

+0

ありがとうございました!私はこれを初めて知り、それが私が逃したシンプルなものになると思った。ありがとう!! – sixstatesaway

3

おそらく、あなたはYESの代わりに、この行のNOrepeatsを設定したい:

[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timeFormatted:) userInfo:nil repeats:NO]; 

サイドノートでは、この行が間違っている:

- (NSString *)timeFormatted:(int)totalSeconds 

それは次のようになります。

- (void)timeFormatted:(NSTimer *)timer 
関連する問題