【问题标题】:MKAnnotationView's subtitle not getting reloadedMKAnnotationView 的字幕没有重新加载
【发布时间】:2010-12-22 10:14:29
【问题描述】:

我目前有一个正在处理我的 NSXMLParser 的 XML 模型;处理后,我的模型中有大约 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

感谢您的宝贵意见。

【问题讨论】:

    标签: cocoa-touch ios ios4 mapkit


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-05-24
      • 2012-05-19
      • 2019-01-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多