MKAnnotationView字幕没有重新加载

时间:2010-12-22 10:14:30

标签: cocoa-touch ios ios4 mapkit

我目前有一个XML模型正在处理我的NSXMLParser;处理后我在模型中得到大约340个对象。我将所有对象放在我的MKMapView上。一旦用户“选择”一个对象(MKAnnotationViewPin);一旦我开始,标题就会填充,coords(duh?)但副标题设置为占位符。我处理另一个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 个答案:

答案 0 :(得分:2)

显然没有人知道......我刚刚发现了这种技术:

- (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];
    }
}