I am creating a MKMapView in a method named "generateMap". From inside viewDidLoad, this works:
[self generateMap];
but this causes the map to quickly load and then disappear, leaving only the blank grey grid:
[NSThread detachNewThreadSelector:@selector(generateMap) toTarget:self withObject:nil];
Any ideas why this might be happening when I call the method through a thread?
I ended up doing this:
-(void)viewDidLoad {
[NSThread detachNewThreadSelector:@selector(spinTheSpinner) toTarget:self withObject:nil];
[self performSelectorOnMainThread:@selector(generateMap) withObject:nil waitUntilDone:NO];
[super viewDidLoad];
}
This allows me to have a spinner (UIActivityIndicator) and load the MKMapView as I want. I set "waitUntilDone:No]" so that the screen switches the MapView before it is done with generateMap. Otherwise, we would not see the spinner and would only see a blank screen until generateMap was done.