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 7736427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:43:41+00:00 2026-06-01T07:43:41+00:00

I’ve created a mapview which has a button to switch between an ‘edit’ mode

  • 0

I’ve created a mapview which has a button to switch between an ‘edit’ mode and a ‘drag’ mode based on the project requirements. I realize that it’s easy enough to have your annotations draggable from creation by setting them draggable in the viewForAnnotation, but the behavior required won’t allow this. I’ve tried a couple different ways of changing the annotations to draggable without success. The first thought was to loop through the existing annotations and set each one to ‘draggable’ and ‘selected’, but I get an unrecognized selector sent to instance error (I did try instantiating a new annotation to pass in the object and re-plot while in the loop, but I get the same error as well):

NSLog(@"Array Size: %@", [NSString stringWithFormat:@"%i", [mapView.annotations count]]);

    for(int index = 0; index < [mapView.annotations count]; index++) {

        if([[mapView.annotations objectAtIndex:index]isKindOfClass:[locAnno class]]){
            NSLog(@"** Location Annotation at Index: %@", [NSString stringWithFormat:@"%i", index]);
            NSLog(@"* Location Marker: %@", [mapView.annotations objectAtIndex:index]);
        }

        if([[mapView.annotations objectAtIndex:index]isKindOfClass:[hydAnno class]]) {
            NSLog(@"** Hydrant Annotation at Index: %@", [NSString stringWithFormat:@"%i", index]);
            NSLog(@"* Hydrant Marker: %@", [mapView.annotations objectAtIndex:index]);

            [[mapView.annotations objectAtIndex:index]setSelected:YES];
            [[mapView.annotations objectAtIndex:index]setDraggable:YES];
        }
    }

The second thought was to use ‘didSelectAnnotationView’, and set selected and draggable on the annotation when it’s selected, and reset the properties when the mode switches back again. This works, but very poorly as the event doesn’t always fire and your left to tap the annotation one or more times before it will change the properties:

- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view {
NSLog(@"Annotation Selected!");
if(!editMode) {
    view.selected = YES;
    view.draggable = YES;
}

}

The first attempt seems the most simple solution if I can get it to work. Using the didSelect method on the other hand is cumbersome and hack-licious. I’m quite new to iOS development, so I apologize if I’ve overlooked something novice while hammering away at this. I appreciate any insight the community can offer. Thanks much.

  • 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-01T07:43:43+00:00Added an answer on June 1, 2026 at 7:43 am

    The first method is better than using the didSelectAnnotationView delegate method.

    The problem with the code which causes the “unrecognized selector” error is that it is calling setSelected: and setDraggable: on the annotation objects (type id<MKAnnotation>) instead of their corresponding MKAnnotationView objects. The id<MKAnnotation> objects don’t have such methods so you get that “unrecognized selector” error.

    The map view’s annotations array contains references to the id<MKAnnotation> (data model) objects — not the MKAnnotationView objects for those annotations.

    So you need to change this:

    [[mapView.annotations objectAtIndex:index]setSelected:YES];
    [[mapView.annotations objectAtIndex:index]setDraggable:YES];
    

    to something like this:

    //Declare a short-named local var to refer to the current annotation...
    id<MKAnnotation> ann = [mapView.annotations objectAtIndex:index];
    
    //MKAnnotationView has a "selected" property but the docs say not to set
    //it directly.  Instead, call deselectAnnotation on the annotation...
    [mapView deselectAnnotation:ann animated:NO];
    
    //To update the draggable property on the annotation view, get the 
    //annotation's current view using the viewForAnnotation method...
    MKAnnotationView *av = [mapView viewForAnnotation:ann];
    av.draggable = editMode;
    

    You must also update the code in the viewForAnnotation delegate method so that it also sets draggable to editMode instead of a hard-coded YES or NO so that if the map view needs to re-create the view for the annotation after you’ve already updated it in the for-loop, the annotation view will have the right value for draggable.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
In my XML file chapters tag has more chapter tag.i need to display chapters

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.