如何在重置标题/副标题后调整标注气泡的大小

时间:2010-10-13 23:26:14

标签: objective-c annotations title mkannotationview callouts

我创建了一个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?
 }

}

1 个答案:

答案 0 :(得分:0)

仍有一些问题,但可能会越来越近。我试过这个,但仍然没有运气。我部分地使用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";