Note that there are some explanatory texts on larger screens.

plurals
  1. POReusing custom drawn annotation view
    primarykey
    data
    text
    <p>I've managed to draw numbers inside custom colored circle annotations (based on <a href="https://stackoverflow.com/questions/7825220/draw-text-in-circle-overlay">this</a>). I want to make some optimizations for my custom annotation class and I read about reusing. My problem is if I make the stuff reusable, the annotation views get mixed on map which is a big problem. The custom drawn annotation views cannot be reused ? Or is it somehow related to the view's annotaion ? I mean, the annotation stores the number to be drawn on its view, practically it's a 1to1 relationship between annotation and its view. </p> <p>Here is my relevant code : Custom annotationview's init : </p> <pre><code>-(id)initWithAnnotation:(id&lt;MKAnnotation&gt;)annotation reuseIdentifier:(NSString *)reuseIdentifier imageType:(int)imageType { self = [super initWithAnnotation: annotation reuseIdentifier: reuseIdentifier]; if (self != nil) { if ([annotation isKindOfClass:[CircleMarker class]]) { // custom annotation class with some extra fields CircleMarker * clm = (CircleMarker * )annotation; self.locationMarker = clm; // ... setting frame and other stuff self.image = [self getImage]; /* this method DRAWS image based on clm */ self.canShowCallout = NO; } ... } </code></pre> <p>And the delegate : </p> <pre><code>- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id &lt;MKAnnotation&gt;)annotation{ static NSString *reuseId_small = @"smallcircle"; static NSString *reuseId_big = @"bigcircle"; CircleAnnotationView * nca = nil; if ((int)[self.mapView getZoomLevel] &lt; ZOOM_LEVEL_FOR_NUMBERS) { nca = (CircleAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:reuseId_small]; if (nca == nil ) nca = [[[CircleAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:reuseId_small imageType:2] autorelease]; } else { nca = (CircleAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:reuseId_big]; if ( nca == nil ) nca = [[[CircleAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:reuseId_big imageType:1] autorelease]; } return nca; } </code></pre> <p>I've tried to replace the <code>self.image =</code> part with a custom <code>drawRect</code> function, but the result was the same.</p> <p>Thanks.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload