views:

13

answers:

1

Hi all,

I created an MKAnnotation name PushPin which has a title and subtitle. I want to be able to dynamically change the title at a later time. I'm close so I'd rather not have to make a whole new AnnotationView, but if I have to I guess that's ok too. My problem is that, once I change the text for the title, the window does not resize and some text might get cut off depending on how big the title originally was.

1) Is there an event I can trigger to resize the callout bubble window again?

2) Also, I check to make sure that the annotation actually has a title first before I go resetting the title, but I had some trouble casting it after I checked, can someone help me out with this? I'm still new to objective-c and this one messed with me for a while.


#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?
 }

}
A: 

Still having some problems, but getting closer maybe. I tried this, but still no luck. I am partially drawing on the code from 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]];
}

Good news is that, I figured out my casting problem, for others who may be curious.

((PushPin *)view.annotation).title = @"test";
Ben Holland
I also tried, [self willChangeValueForKey:@"title"]; // Workaround for SDK 3.0, otherwise callout info won't update. [self didChangeValueForKey:@"title"]; // Workaround for SDK 3.0, otherwise callout info won't update.
Ben Holland
It seems, MKAnnotationCalloutInfoDidChangeNotification is depreciated, http://developer.apple.com/library/ios/#documentation/MapKit/Reference/MKAnnotationView_Class/Reference/Reference.html What should I be using instead?
Ben Holland
Note: The very last entry on this forum seems to describe my problem. http://www.iphonedevsdk.com/forum/iphone-sdk-development/50522-draggable-annotation-mkmapview.html Is it possible that because I'm trying to change the title in the touch event that the redraw for the callout isn't happening until the next touch event?
Ben Holland
This seems to be a possible solution to my problem. But for the life of me I can't figure it out. http://stackoverflow.com/questions/978897/how-to-trigger-mkannotationviews-callout-view-without-touching-the-pin
Ben Holland