Note that there are some explanatory texts on larger screens.

plurals
  1. POiphone mkannotationview strange problem - possibly being reused
    primarykey
    data
    text
    <p>I've just found a strange issue with my sub classed mkannotationview.</p> <p>When I add the first 5 markers, they all work perfectly. In the mkannotationview sub class, I NSLog a message which I see 5 times. However, when I remove ALL the markers and redraw them - using all the same methods, I see the NSLog only once. </p> <p>It's like the map is reusing existing annotationviews? Is there a way to force it to use new ones each time? </p> <p>[UPDATE with code]</p> <p>So the reason I cannot reuse (and this may or may not be the problem) is that I am creating unique markers with a label. The label on the marker contains a reference to the individual marker (consider it like a product ID)</p> <p>So... in ProductPlot.h</p> <pre><code>@interface ProductPlot : NSObject &lt;MKAnnotation&gt; { NSString *productID; float latitude; float longitude; } @property (nonatomic, copy) NSString *productID; </code></pre> <p>and ProductPlot.m</p> <pre><code>@implementation ProductPlot @synthesize productID; - (CLLocationCoordinate2D)coordinate { CLLocationCoordinate2D coord = {self.latitude, self.longitude}; return coord; } - (NSString *) productID { return productID; } </code></pre> <p>then I have the annotation view sub classed as ProductPlotView.h</p> <pre><code>@interface ProductPlotView : MKAnnotationView { ProductPlot *product; } </code></pre> <p>and in ProductPlotView.m</p> <pre><code>@implementation ProductPlotView - (id)initWithAnnotation:(id &lt;MKAnnotation&gt;)annotation reuseIdentifier:(NSString *)reuseIdentifier { if(self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier]) { product = (ProductPlot *)annotation; UILabel *plate2 = [[[UILabel alloc] init] autorelease]; plate2.text = product.productID; plate2.frame = CGRectMake(35, 4, 100, 30); plate2.backgroundColor = [UIColor clearColor]; //]clearColor]; [plate2 setFont: [UIFont fontWithName: @"myFont" size: plate2.font.pointSize]]; [self addSubview:plate2]; } self.frame = CGRectMake(0,0,133,40); return self; } </code></pre> <p>So then in my code, I plot the points using</p> <pre><code>- (void)plotPoint: (int) y latitude: (double) lat longitude: (double) lng productID: (NSString *) pID { ProductPlot *newAnnotation = [[ProductPlot alloc] init]; newAnnotation.latitude = lat; newAnnotation.longitude = lng; newAnnotation.productID = pID; [mapView addAnnotation:newAnnotation]; [newAnnotation release]; } </code></pre> <p>I also have the code to handle the annotations.</p> <pre><code>- (MKAnnotationView *)mapView:(MKMapView *)lmapView viewForAnnotation:(id &lt;MKAnnotation&gt;)annotation { ProductPlotView *eventView = (ProductPlotView *)[lmapView dequeueReusableAnnotationViewWithIdentifier:@"eventview"]; if(eventView == nil) { eventView = [[[VehicleViewInfo alloc] initWithAnnotation:annotation reuseIdentifier:@"eventview"] autorelease]; } eventView.annotation = annotation; return eventView; } </code></pre> <p>So... the above will take the productID and place it on a label which is the map marker. This seems to work perfectly on the FIRST plot instance, but if I remove the markers (using <code>[mapView removeAnnotations:mapView.annotations];</code>) then call this function again, it draws the points OK, but the product IDs are not correct. It appears to draw them at random. </p> <blockquote> <p>NOTE: the code above has had a few parts removed, so there may be typos</p> </blockquote> <p>Thanks for any info.</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.
    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