Субтитры MKAnnotationView не загружаются - PullRequest
1 голос
/ 22 декабря 2010

В настоящее время у меня есть обрабатываемая модель XML, мой NSXMLParser;Я получаю около 340 объектов в моей модели после обработки.Я размещаю все объекты на моем MKMapView.Как только пользователь «выбирает» объект (MKAnnotationViewPin);как только я начинаю, заголовок заполняется, координаты тоже (да?), но субтитры устанавливаются в качестве заполнителя.Я обрабатываю другой XML-файл для получения дополнительной информации, субтитры обновляются и заполняются.

Как только XML-файл анализируется, я получаю уведомление и обновляю его объект <MKAnnotation> для отражения измененных субтитров.Чтобы отразить изменение на карте, я должен «отменить выбор» булавки и щелкнуть ее еще раз, чтобы отобразить изменение.

Вот мой объект <MKAnnotation>:

Заголовок:

@interface CPCustomMapPin : NSObject <MKAnnotation>
{
    NSString *_title;
    NSString *_annotation;
    CLLocationCoordinate2D _coords;
    NSString *stationID;
}

@property (nonatomic, retain) NSString *_title;
@property (nonatomic, retain) NSString *_annotation;
@property (nonatomic) CLLocationCoordinate2D _coords;
@property (nonatomic, retain) NSString *stationID;

- (id) initWithTitle: (NSString *) _title withAnnotation: (NSString *) _annotation withCoords: (CLLocationCoordinate2D) _coords withStationID: (NSString *) _id;

Реализация:

@implementation CPCustomMapPin

@synthesize _title, _annotation, _coords, stationID;

- (id) initWithTitle: (NSString *) __title withAnnotation: (NSString *) __annotation withCoords: (CLLocationCoordinate2D) __coords withStationID: (NSString *) _id
{
    _title = [[NSString alloc] init];
    _annotation = [[NSString alloc] init];
    stationID = [[NSString alloc] init];

    [self set_title: __title];
    [self set_annotation: __annotation];
    [self set_coords: __coords];
    [self setStationID: _id];

    return self;
}

- (NSString *) title
{
    return _title;
}

- (NSString *) subtitle
{
    return _annotation;
}

- (CLLocationCoordinate2D) coordinate
{
    return _coords;
}

- (NSString *) description
{
    return [NSString stringWithFormat: @"title: %@ subtitle: %@ id: %@", _title, _annotation, stationID];
}

- (void) dealloc
{
    [_title release];
    [_annotation release];
    [stationID release];

    [super dealloc];
}

@end

Спасибо за ваш ценный вклад.

1 Ответ

2 голосов
/ 22 декабря 2010

Видимо никто не знает ... Я только что нашел эту технику:

- (void) closeAnnotation: (id <MKAnnotation>) annotation inMapView: (MKMapView *) mapView
{
    [mapView deselectAnnotation: annotation animated: NO];
    [mapView selectAnnotation: annotation animated: YES];
}

И, конечно, вы называете свой метод соответственно:

Пример:

- (void) myMethod
{
    for (id <MKAnnotation> _annotation in mapView.annotations)
    {
        [self closeAnnotation: _annotation inMapView: mapView];
    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...