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 に答える