Replacing calloutaccessoryview in mkannotationview

In my viewForAnnotation viewForAnnotation I create a MKAnnotationView with leftCalloutaccessory as an info button. When the info button is pressed, I want to replace it with a UIActivityIndicator . Therefore, in the calloutAccessoryTapped calloutAccessoryTapped I wrote view.leftCalloutaccessoryView = [UIActivityIndicator indicatorWithStyle:UIActivityIndicatorWhite];

The callout accessory seems to be changing, but it seems that the view is not being updated immediately.

That when the leader’s accessory hides (by clicking another contact) and opens again, I see a counter. But otherwise, I do not.

I tried calling [view setNeedsdisplay] and [view setNeedsLayout] and [view layoutsubviews] , but in vain.

Any suggestions / pointers?

+4
source share
2 answers

I would consider deleting and re-adding annotations. It seems a little heavy, but it can work.

0
source

I had a similar problem - I needed to display an image for leftCalloutAccessoryView if it was associated with an annotation. Try setting it to mapView: didSelectAnnotationView instead of mapView: viewForAnnotation

 -(void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)annotView { ... if(imgURL.length>1){ // set a thread that will load the image // but don't set the leftCalloutAccessoryView until the image is loaded dispatch_queue_t downloader = dispatch_queue_create("annotation image downloader",NULL); dispatch_async(downloader, ^{ NSURL* photoURL = [NSURL URLWithString:imgURL]; NSData* photoData = [NSData dataWithContentsOfURL:photoURL]; UIImage* photoImage = [UIImage imageWithData:photoData]; dispatch_async(dispatch_get_main_queue(), ^{ annotView.leftCalloutAccessoryView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 32, 32)]; [(UIImageView *) annotView.leftCalloutAccessoryView setImage:photoImage]; }); }); } } 
0
source

Source: https://habr.com/ru/post/1306010/


All Articles