我创建了一个具有标题和副标题的MKAnnotation名称PushPin。我希望以后可以动态更改标题。我已经接近了,所以我不想做一个全新的AnnotationView,但是如果我必须的话,我想那也是可以的。我的问题是,一旦更改了标题的文本,窗口就不会调整大小,并且某些文本可能会被截断,具体取决于标题的大小。

1)是否可以触发一个事件以再次调整标注气泡窗口的大小?

2)另外,在重新设置标题之前,我要检查以确保注释实际上首先具有标题,但是在检查之后,我在投射它时遇到了一些麻烦,有人可以帮我解决这个问题吗?我对Objective-C还是陌生的,这使我有些困惑。



#import <Foundation/Foundation.h>
#import <MapKit/MKAnnotation.h>

@interface PushPin : NSObject <MKAnnotation> {
 CLLocationCoordinate2D _coordinate;
 NSString *_title;
 NSString *_subtitle;
 NSString *_ID;
}

@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;
@property (nonatomic, retain) NSString *title;
@property (nonatomic, retain) NSString *subtitle;
@property (nonatomic, retain) NSString *ID;

- (id) initWithCoordinateAndInformation:(CLLocationCoordinate2D)coordinate title:(NSString *)title subtitle:(NSString *)subtitle;

@end




- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
 NSLog(@"Annotation was TAPPED!");

 if ([view.annotation isKindOfClass:[PushPin class]]) {
  view.annotation.title = @"test";

          // warning here, that this might not be implemented...
          // but it is for this class type, how do I cast it to the correct type?
 }

}

最佳答案

仍然有一些问题,但可能会越来越近。我试过了,但还是没有运气。我部分借鉴了http://digdog.tumblr.com/post/252784277/mapkit-annotation-drag-and-drop-with-callout-info中的代码

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view
{
    NSLog(@"Annotation was TAPPED!");

    if ([view.annotation isKindOfClass:[PushPin class]]) {
        ((PushPin *)view.annotation).title = @"test";
    }

    [self willChangeValueForKey:@"subtitle"]; // Workaround for SDK 3.0, otherwise callout info won't update.
    [self didChangeValueForKey:@"subtitle"]; // Workaround for SDK 3.0, otherwise callout info won't update.

    [[NSNotificationCenter defaultCenter] postNotification:[NSNotification notificationWithName:@"MKAnnotationCalloutInfoDidChangeNotification" object:self]];
}


好消息是,对于其他可能好奇的人,我发现了铸造问题。

((PushPin *)view.annotation).title = @"test";

07-24 09:37
查看更多