How to change leader size after resetting title / subtitle

I created the name MKAnnotation PushPin, which has a title and subtitles. I want to be able to dynamically change the name later. I am close, so I would not need to create a completely new AnnotationView, but if I need to guess that everything is in order. My problem is that as soon as I change the text for the title, the window does not change the size, and some text may be cut depending on how significant the title was.

1) Is there an event that I can trigger to resize the call bubbles window again?

2) In addition, I check that the annotation actually has a title before I proceed to reset the title, but I am having trouble checking it after checking, can anyone help me with this? I'm still new to objective-c, and this one is with me from time to time.


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

}
+3
source share
1 answer

There are still some problems, but maybe closer. I tried this, but still no luck. I partially draw 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]];
}

The good news is that I found out my casting problem for others who might be interested.

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

Source: https://habr.com/ru/post/1769441/


All Articles