MKAnnotationView 的字幕未重新加载

发布于 2024-10-08 11:16:39 字数 1970 浏览 1 评论 0原文

我目前有一个 XML 模型正在由 NSXMLParser 进行处理;处理后,我的模型中得到了大约 340 个对象。我将所有对象放置在 MKMapView 上。一旦用户“选择”一个对象(MKAnnotationViewPin);一旦我开始,标题和坐标都会被填充(废话?),但副标题被设置为占位符。我处理另一个 XML 文件以检索额外信息,副标题得到更新和填充。

一旦 XML 文件被解析,我就会收到通知并更新其 对象以反映更改后的字幕。为了在地图上反映更改,我必须“取消选择”该图钉并再次单击它以显示更改。

这是我的 对象:

标题:

@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

感谢您的宝贵意见。

I currently have an XML model getting processed my an NSXMLParser; I get about 340 objects in my model after processing. I place all of the objects on my MKMapView. Once a user "selects" an object (MKAnnotationViewPin); once I start off, the title is populated, coords too (duh?) but the subtitle is set to a place-holder. I process another XML file to retrieve extra information, the subtitle gets updated and populated.

Once the XML file gets parsed I get notified and update its <MKAnnotation> object to reflect the changed subtitle. To reflect the change on the map I have to "unselect" the pin and click it again for it to show the change.

Here is my <MKAnnotation> object:

Header:

@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:

@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

Thank you for your valuable input.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

七月上 2024-10-15 11:16:39

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

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

Apparently no one knows… I just found this technique:

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

And of course you call your method accordingly:

Example:

- (void) myMethod
{
    for (id <MKAnnotation> _annotation in mapView.annotations)
    {
        [self closeAnnotation: _annotation inMapView: mapView];
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文