バックグラウンド スレッドを使用してラベルの 1 つを更新しています
次のコードを使用しています。しかし、iOS 4.0 では、アプリケーションがその状態を保存してバックグラウンドに移行することを知りました。私のアプリケーションもその作業を行いましたが、使用しているスレッドは、アプリケーションを非表示にすると動作を停止し、再度開くと元の場所から再開します。スレッドをバックグラウンドで実行し続け、アプリケーションが非表示になっている間に GUI を変更するには、コードで何を変更する必要があるか教えてください。私はこのコードを使用しています..
-(void)startThread
{
NSThread *thread = [[NSThread alloc] initWithTarget:self selector:@selector(setUpTimerThread) object:nil];
[thread start];
}
-(void)setUpTimerThread
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSTimer *timer = [NSTimer timerWithTimeInterval:3 target:self selector:@selector(triggerTimer) userInfo:nil repeats:YES];
NSRunLoop *runLoop = [NSRunLoop currentRunLoop];
[runLoop addTimer:timer forMode:NSRunLoopCommonModes];
[runLoop run];
[pool release];
}
-(void)triggerTimer
{
NSLog(@"***Timer Called after 3 seconds*** %d",count);
self.label.text = [NSString stringWithFormat:@"count value = %d",count];
//self.titleLabel.text= [NSString stringWithFormat:@"count value = %d",count];
count = count +1;
}
ありがとう