0
votes

I'm having some problems with my thread. Currently, the view brought up by showInstructions is disabled until the thread is done... how can I make it interactive while the thread is going on?

Thanks in advance!

 [self performSelectorOnMainThread:@selector(loadEverything) withObject:self waitUntilDone:YES];


    -(void)loadEverything {    
        NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

        [self performSelector:@selector(showInstructions)];
        [self performSelector:@selector(loadStats)];
        [self performSelector:@selector(animate_sideBTN)];
        [self performSelector:@selector(loadNIBs)];
        [self performSelector:@selector(incrementStats)];

        [NSThread detachNewThreadSelector:@selector(loadMap) toTarget:self withObject:nil];

        [[self.view viewWithTag: 123] removeFromSuperview];
        [pool drain];
        }
2
You are calling that method on a new thread, but you are still calling everything on the main thread, so it's probably blocking it. Do you NEED to call those methods on the main thread? - EmilioPelaez
I don't think they all need to be on the main thread... I just want the showInstructions to not freeze. Advice? - Adam Storr
As a rule of thumb, you should never do any UI updates on a background thread. - Christopher A
Does that include adding annotations to a map? - Adam Storr
Yes. In that case, let the background operation return an NSArray back to the main thread, then add the NSArray to the MKMapView synchronously. - Christopher A

2 Answers

1
votes

Please try calling -(void)loadEverything in "performSelectorOnMainThread" and from that call [NSThread detachNewThreadSelector:] for operation which are not affecting UI components and [self performSelector] for which are affecting UI components.

0
votes

I think you should learn some GCD and do the same code inside a block. Or use an NSOperation… Avoid threads if possible.