I am trying to run NSTimer in a stream using the iPhone SDK 3.0. I think I'm doing everything right (new runloop, etc.). If I call [timer invalidate] on viewDidDissappear, although I get this error:
bool _WebTryThreadLock (bool), 0x3986d60: tried to get a web lock from a thread other than the main thread or web thread. This may be the result of calling UIKit from the secondary stream. Failure now ... Program signal: "EXC_BAD_ACCESS".
Here is my code:
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[activityIndicator startAnimating];
NSThread* timerThread = [[NSThread alloc] initWithTarget:self selector:@selector(timerStart) object:nil];
[timerThread start];
}
-(void)timerStart
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSRunLoop* runLoop = [NSRunLoop currentRunLoop];
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];
}
When I delete a line, an invalid timer, everything works fine. Shouldn't I invalidate this, or am I making some other mistake?
thank
source
share