Queue code after StartAnimating on Main thread again. You can use
- dispath_asyn
- PerformSelectorOnMainThread
- PerformSelectorInBackground
All three should work just fine.
-(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
if (!self.activityIndicator) {
NSLog(@"error");
}
self.activityIndicator.hidden = NO;
[self.mapView addSubview:self.activityIndicator];
[self.activityIndicator startAnimating];
dispatch_async(dispatch_get_main_queue(), ^(void) {
if ([view.leftCalloutAccessoryView isKindOfClass:[UIImageView class]]) {
UIImageView *imageView = (UIImageView *)(view.leftCalloutAccessoryView);
if ([view.annotation respondsToSelector:@selector(thumbnail)]) {
imageView.image = [view.annotation performSelector:@selector(thumbnail)];
}
[self.activityIndicator stopAnimating];
}
});
}
Explanation: If you do to UI operation without queuing up the operations in main thread effect wont be visible because UI wont show any activity until and unless you finish running the thread and move to next operating in main thread. Same is valid for addSubview removeSubview too.