iPhoneSDK3.0を使用してスレッドでNSTimerを実行しようとしています。私はすべてを正しく行っていると思います(新しいrunloopなど)。このエラーが発生したにもかかわらず、viewDidDissappearで[timer invalidate]を呼び出すと、次のようになります。
bool _WebTryThreadLock(bool)、0x3986d60:メインスレッドまたはWebスレッド以外のスレッドからWebロックを取得しようとしました。これは、セカンダリスレッドからUIKitを呼び出した結果である可能性があります。現在クラッシュしています...プログラムは信号「EXC_BAD_ACCESS」を受信しました。
これが私のコードです:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[activityIndicator startAnimating];
NSThread* timerThread = [[NSThread alloc] initWithTarget:self selector:@selector(timerStart) object:nil]; //Create a new thread
[timerThread start]; //start the thread
}
-(void)timerStart
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSRunLoop* runLoop = [NSRunLoop currentRunLoop];
//Fire timer every second to updated countdown and date/time
timer = [[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(method) userInfo:nil repeats:YES] retain];
[runLoop run];
[pool release];
}
- (void)viewDidDisappear:(BOOL)animated {
[super viewDidDisappear:animated];
[timer invalidate];
}
タイマーを無効にする行を削除すると、すべてが正常に機能します。私はそれを無効にすることになっていないのですか、それとも他の間違いを犯していますか?
ありがとう