Я только что обнаружил странную проблему с моим подклассом mkannotationview.
Когда я добавляю первые 5 маркеров, они все работают отлично.В подклассе mkannotationview я NSLog сообщение, которое я вижу 5 раз.Однако, когда я удаляю ВСЕ маркеры и перерисовываю их - используя все те же методы, я вижу NSLog только один раз.
Это как карта повторно использует существующие аннотации?Есть ли способ заставить его использовать новые каждый раз?
[ОБНОВЛЕНИЕ с кодом]
Так что я не могу использовать повторно (и это может или не может быть проблемой) в том, что я создаю уникальные маркеры с меткой.Метка на маркере содержит ссылку на отдельный маркер (рассматривайте его как идентификатор продукта)
Итак ... в ProductPlot.h
@interface ProductPlot : NSObject <MKAnnotation> {
NSString *productID;
float latitude;
float longitude;
}
@property (nonatomic, copy) NSString *productID;
и ProductPlot.m
@implementation ProductPlot
@synthesize productID;
- (CLLocationCoordinate2D)coordinate {
CLLocationCoordinate2D coord = {self.latitude, self.longitude};
return coord;
}
- (NSString *) productID {
return productID;
}
тогда у меня есть подпункт представления аннотации, классифицируемый как ProductPlotView.h
@interface ProductPlotView : MKAnnotationView {
ProductPlot *product;
}
и в ProductPlotView.m
@implementation ProductPlotView
- (id)initWithAnnotation:(id <MKAnnotation>)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;
}
Итак, в моем коде я строю графикточки, использующие
- (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];
}
У меня также есть код для обработки аннотаций.
- (MKAnnotationView *)mapView:(MKMapView *)lmapView viewForAnnotation:(id <MKAnnotation>)annotation {
ProductPlotView *eventView = (ProductPlotView *)[lmapView
dequeueReusableAnnotationViewWithIdentifier:@"eventview"];
if(eventView == nil) {
eventView = [[[VehicleViewInfo alloc] initWithAnnotation:annotation
reuseIdentifier:@"eventview"]
autorelease];
}
eventView.annotation = annotation;
return eventView;
}
Так что ... приведенное выше возьмет productID и поместит его на этикетку, которая является картоймаркер.Кажется, это отлично работает на экземпляре FIRST plot, но если я удаляю маркеры (используя [mapView removeAnnotations:mapView.annotations];
), затем вызываю эту функцию снова, она рисует точки ОК, но идентификаторы продукта неверны.Похоже, чтобы нарисовать их наугад.
ПРИМЕЧАНИЕ. В приведенном выше коде было удалено несколько частей, поэтому возможны опечатки
Спасибо за любую информацию.