私は、nuitimerを内部に持つタイマークラスを持っていて、誰かがuitableviewcontrollerにプッシュ通知を送り、通知オブジェクト(タイマーの値)はuitableviewcellの影響を受けます。私の問題は、私がスクロールするために画面をタッチすると、タイマの停止、NSTimerは他のスレッドで起動しないのですか?どのように私はこの問題を解決することができます。nstimerが画面に触れると止まる
マイtimerClass#import "timerEtape.h"
#import "FonctionUtile.h"
#import "Mission.h"
static timerEtape *sngTimerEtape = nil;
@implementation timerEtape
@synthesize repeatingTimerEtape;
@synthesize dateComp;
@synthesize questionCircuit;
@synthesize b_Pause;
+(timerEtape *) singletonTimer
{
@synchronized(self){
if (sngTimerEtape == nil)
{
sngTimerEtape = [[timerEtape alloc]init];
}
}
return sngTimerEtape;
}
-(id)init
{
self = [super init];
if (self != nil) {
dateComp = [[NSDateComponents alloc] init];
b_Pause = FALSE;
}
return self;
}
- (void)startTimer {
[repeatingTimerEtape invalidate];
NSString * temps;
if (questionCircuit) {
temps = [[Mission singletonMission].circuitTerrain valeurChampEtapeCircuitEnCours:@"et_temps_etape" :FALSE];
}
else {
temps = [[Mission singletonMission].histoireTerrain valeurChampQuestion:@"hi_temps_etape" :FALSE];
}
if (!b_Pause) {
[dateComp setHour:0];
[dateComp setMinute:[[FonctionUtile gauche:temps :2] intValue]];
[dateComp setSecond:[[FonctionUtile droite:temps :2] intValue]];
}
else {
b_Pause = FALSE;
}
self.repeatingTimerEtape = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(updateLabelTimerEtape:) userInfo:nil repeats:YES];
}
-(void)pause
{
self.b_Pause = TRUE;
[repeatingTimerEtape invalidate];
}
-(void)updateLabelTimerEtape:(NSTimer*)theTimer
{
if ([dateComp second] == 0) {
if ([dateComp minute] == 0) {
if ([dateComp hour] != 0) {
[dateComp setHour:[dateComp hour] -1];
[dateComp setMinute:59];
[dateComp setSecond:59];
}
else {
[repeatingTimerEtape invalidate];
[delegate performSelector:touchAction];
}
}
else {
[dateComp setMinute:[dateComp minute] -1];
[dateComp setSecond:59];
}
}
else {
[dateComp setSecond:[dateComp second] -1];
}
[[NSNotificationCenter defaultCenter] postNotificationName:@"rafraichirTimerEtape" object:[NSString stringWithFormat:@"%02d:%02d", [dateComp minute],[dateComp second]]];
}
-(void)setTarget:(id)target andAction:(SEL)action {
delegate = target;
touchAction = action;
}
-(void)dealloc
{
[dateComp release];
[repeatingTimerEtape release];
[super dealloc];
}
@end
と私は私のUITableViewControllerクラス
-(void)rafraichirTimerEtape:(NSNotification*)notification
{
[tempsRestant release];
tempsRestant = [[notification object]copy];
[table cellForRowAtIndexPath:[NSIndexPath indexPathForRow:2 inSection:0]].detailTextLabel.text = [notification object];
}
ありがとう
ニースの答えを使用しています。小さなコードのサンプルをお探しですか? –