3

我创建了一个具有标题和副标题的 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?
 }

}
4

1 回答 1

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";
于 2010-10-15T16:34:10.540 回答