アプリのサーバーからsecondsToEnd値を使用して情報を取得し、この情報を受信した後にカウンターを開始します。
私のプロジェクトにはスクロールビューが含まれているので、スクロールによるタイマーのロックを回避するには、次の方法でタイマーをNSRunLoopに追加します。
[[NSRunLoop currentRunLoop] addTimer:timer
forMode:NSRunLoopCommonModes];
NSTimerプロパティを作成しました。これは、どのようにオリジナルで、タイマーであり、これは私のstartTimer関数のスニペット全体です。
- (void)startTimer
{
if (_timer || [_timer isValid]) [_timer invalidate], _timer = nil, [_timer release];
NSTimer * timer = [[NSTimer alloc] initWithFireDate:[NSDate date]
interval:1.0
target:self
selector:@selector(timer:)
userInfo:nil
repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:timer
forMode:NSRunLoopCommonModes];
[self setTimer:timer];
[timer release];
}
startメソッドでチェックが無効になる理由は、secondsToEnd値が0に達した後、新しい値を受け取り、startTimerを再度呼び出すためです。
そして私のdeallocメソッドではこれがあります:
if (_timer || [_timer isValid]) [_timer invalidate], _timer = nil, [_timer release];
しかし、それは無効になりませんか?私は何が間違っているのですか?