Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8024429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:52:13+00:00 2026-06-04T22:52:13+00:00

I have a MKMapView with a callout. When the callout (detail disclosure indicator) button

  • 0

I have a MKMapView with a callout. When the callout (detail disclosure indicator) button is pressed, it shows a detailViewController. I want to add the ability to change the map type and pin color for my annotation. So I currently do this:

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {

    DetailMapViewController *destination = [[DetailMapViewController alloc] initWithNibName:@"DetailMapViewController" bundle:nil];
    UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:destination];

    if ([destination  respondsToSelector:@selector(setDelegate:)]) {
        [destination setValue:self forKey:@"delegate"];
    }
    if ([destination respondsToSelector:@selector(setPlacemark:)]) {
        [destination setValue:_currentPlacemark forKey:@"Placemark"];
    }
    if ([destination respondsToSelector:@selector(setMapTypeAsNum:)]) {
        [destination setValue:[NSNumber numberWithInteger:self.mapView.mapType] forKey:@"mapTypeAsNum"];

        [destination addObserver:self forKeyPath:@"mapTypeAsNum" options:NSKeyValueObservingOptionNew context:NULL];
    }
    if ([destination respondsToSelector:@selector(setColorAsNum:)]) {
        [destination setValue:[NSNumber numberWithInteger:MKPinAnnotationColorPurple] forKey:@"colorAsNum"];

        [destination addObserver:self forKeyPath:@"colorAsNum" options:NSKeyValueObservingOptionNew context:NULL];
    }
    [self presentModalViewController:navController animated:YES];
}

In my observeValueForKeyPath method:

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
    DetailMapViewController *destination = (DetailMapViewController *)object;
    [destination removeObserver:self forKeyPath:@"mapTypeAsNum"];
    [destination removeObserver:self forKeyPath:@"colorAsNum"];

    if ([keyPath isEqualToString:@"mapTypeAsNum"]) {
        if ([object isKindOfClass:[DetailMapViewController class]]) {
            id mapType = [change objectForKey:NSKeyValueChangeNewKey];
            self.mapView.mapType = [mapType integerValue];
        }
    }
    else if ([keyPath isEqualToString:@"colorAsNum"]) {
        if ([object isKindOfClass:[DetailMapViewController class]]) {
            id pinColor = [change objectForKey:NSKeyValueChangeNewKey];
            MKPinAnnotationView *annotationView = (MKPinAnnotationView *)[self.mapView viewWithTag:10];
            annotationView.pinColor = [pinColor integerValue];
        }
    }
}

The problem with this is I end up leaking observation info according to the Console if I don’t change the pin color or map type in the DetailViewController to call the observeValueForKeyPath method. So I was wondering where I am to add the observer and remove the observer in a scenario like this. In the past using NSNotificationCenter, I would remove the observer in dealloc, and add the observer just before presenting the detailViewController similar to the above code. But with KVO, I’m not sure how this works. Any thoughts? Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T22:52:14+00:00Added an answer on June 4, 2026 at 10:52 pm

    You should stop observing just before the modal view is closed.

    The best way to accomplish this is to have the modal view notify your MKMapView controller when it is ready to be closed and have MKMapView stop observing and then close the modal view.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a MKMapView annotation object that has a right callout accessory detail disclosure
I have a MKMapView that has a pin than when pressed shows the annotation's
I want to add an annotation to a MapView with disclosure button on it
I have a MKmapView in my application. now i want to add frame im
I have MKMapView with MKPlacemark on it. When showing the map, I'm showing place
I have a MKMapView in my iOS application, and would like to add the
I have an MKMapView which allows the user to scroll the map around. Later,
I have a MKMapView (obviously), that shows housing locations around the user. I have
I have an MKMapView in my app and have a button that turns on
I have a MKMapView. I need to add a circle as a radius around

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.