Update mkannotation properties and update annotations

I have mkannotation located on a map that has mkannotationview, as well as calloutview, which when clicked goes to a child uiviewcontroller. I am updating some properties from the callout uiviewcontroller, but after I'm done, I want to move the position of the annotation to the map and change the name of the annotation and subtitles. How can I do this using callout uiviewcontoller? What is the most elegant way to handle this? Sample code would be great if anyone had one.

thanks

+3
source share
4 answers

, MapCallBackDelegate, , . .

@protocol MapCallBackDelegate
    -(void)updateAnnotation:(id)whatEverParamsYouWant;
@end

. ,

@property (nonatomic, retain) id<MapCallBackDelegate> callbackDelegate;

, self

myMapAnnotationView.callbackDelegate = self;

, //, callbkacDelegate.

, , MapAnnotationView.

+1

, . , , .

+1

, @Caleb, coordinate , .

, , setCoordinate, , coordinate assign (, MKPointAnnotation) readonly. KVO .

, , + , .

+1

- . , , , , - :

:

@interface YourController
{
    ...
    MKAnnotation *_latestDetailViewed;
}

... 
@property(nonatomic, retain) MKAnnotation *latestDetailViewed;

@end

.m -

@implementation YourController

... 
@synthesize latestDetailViewed = _latestDetailViewed;

...
-(void) dealloc
{
    ...
    self.latestDetailViewed = nil;
    [super dealloc];
}

-(void) whereverYouLaunchYourDetailScreenFrom:(MKAnnotation*)detailAnnotation
{
    self.latestDetailViewed = detailAnnotation;
    // then create/push your view controller
}

-(void) viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    if(_latestDetailViewed)
    {
        // Do whatever you want to the annotation here
        self.latestDetailViewed = nil;
    }
}

, , . , , NSNotifications.

, , :)

0

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


All Articles