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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:52:37+00:00 2026-05-15T23:52:37+00:00

I am trying to pass a managedObject from a mapView with multiple annotation to

  • 0

I am trying to pass a managedObject from a mapView with multiple annotation to a mapDetailView with only one annotation of the managedObject passed. This works great in a tableView to mapDetaiView. Any help would be appreciated. My code …

- (void)viewDidLoad {
[super viewDidLoad];

if (self.managedObjectContext == nil) { 
    self.managedObjectContext = [(CrossroadsTreasuresAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];
}

// setup the mapView
[mapView removeAnnotations:mapView.annotations];
[mapView setMapType:MKMapTypeStandard];
[mapView setZoomEnabled:YES];
[mapView setScrollEnabled:YES];
[self.view insertSubview:mapView atIndex:0];
[mapView setDelegate:self];

// setup the location coordnates to Victoria, TX
double lat = [@"28.825" doubleValue];
double lng = [@"-97.009" doubleValue];
CLLocationCoordinate2D rcoord;
rcoord.latitude = lat;
rcoord.longitude = lng;

// setup the map region
//MapLocation *annotation = [[MapLocation alloc] init];
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(rcoord, 25000, 25000);
MKCoordinateRegion adjustRegion = [mapView regionThatFits:region];
[mapView setRegion:adjustRegion animated:YES];

NSError *error;
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"GarageSaleItem" inManagedObjectContext:[self managedObjectContext]];
[fetchRequest setEntity:entity];
NSArray *markerObjects = [[self managedObjectContext] executeFetchRequest:fetchRequest error:&error];

for (int i = 0; i < [markerObjects count]; i++) {
    NSDictionary *marker = (NSDictionary *)[markerObjects objectAtIndex:i];

    // Set the annotation coordnates
    double lat = [[marker valueForKey:@"latitude"] doubleValue];
    double lng = [[marker valueForKey:@"longitude"] doubleValue];
    CLLocationCoordinate2D coord;
    coord.longitude = lng;
    coord.latitude = lat;

    // Create the annotation instatnce
    MapLocation *annotation = [[MapLocation alloc] init];

    // Set the annotation display information
    annotation.coordinate = coord;
    annotation.streetAddress = [marker valueForKey:@"streetAddress"];
    annotation.city = [marker valueForKey:@"city"];
    annotation.state = [marker valueForKey:@"state"];
    annotation.zipCode = [marker valueForKey:@"zipCode"];

    // Add the annotation the the map
    [self.mapView addAnnotation:annotation];
    [annotation release];
}
[fetchRequest release];
}


- (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)annotation {
// if it's the user location, just return nil.
if ([annotation isKindOfClass:[MKUserLocation class]])
    return nil;

// handle our two custom annotations
//
if ([annotation isKindOfClass:[MapLocation class]]) {
    // try to dequeue an existing pin view first
    static NSString* AnnotationIdentifier = @"com.coastalbendmedia.pin";
    MKPinAnnotationView* pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationIdentifier];
    if (!pinView) {
        // if an existing pin view was not available, create one
        MKPinAnnotationView* customPinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier] autorelease];

        customPinView.pinColor = MKPinAnnotationColorPurple;
        customPinView.animatesDrop = YES;
        customPinView.canShowCallout = YES;

        // add a detail disclosure button to the callout which will open a new view controller page
        //
        // note: you can assign a specific call out accessory view, or as MKMapViewDelegate you can implement:
        //  - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control;
        //
        UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        customPinView.rightCalloutAccessoryView = rightButton;

        return customPinView;
    } else {
        pinView.annotation = annotation;
    }
    return pinView;
}
return nil;
}


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


DetailViewController *controller = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];

// Pass the selected object to the new view controller.
[self.navigationController pushViewController:controller animated:YES];

// Set the detail item in the detail view controller.
    // THIS IS WHERE MY PROBLEM IS! indexPath Undeclared
NSManagedObject *selectedObject = [[self fetchedResultsController] objectAtIndexPath:indexPath];
controller.detailItem = selectedObject;
[controller release];

}
  • 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-05-15T23:52:38+00:00Added an answer on May 15, 2026 at 11:52 pm

    indexPath is undeclared because you’re not implementing a UITableViewDataSource method in this case! I don’t know what you’re trying to accomplish here, but I think that there could be more than one possible solution. First, you could try to add an object property to your annotation, and use that to get the corresponding NSManagedObject from the annotation. Second, you could use an NSMutableDictionary to store the objects instead of an NSArray. You would use it as follows:

    NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
    
    for(NSManagedObject *object in markerObjects) {
      // Create the annotation
      MapLocation *annotation = [[MapLocation alloc] init];
    
      [dictionary setObject:object forKey:annotation]
    }
    

    Then you would retrieve the corresponding object for an annotation like this:

    - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
      NSManagedObject *object = [dictionary objectForKey:view.annotation];
    
      // Do whatever you want with your object
    }
    

    Please note that MapLocation here must conform to the NSCopying protocol since it is copied by the setObject:forKey: method.

    Third, you could add all the informations (address, city, state, etc.) to your NSManagedObject subclass that conforms to the MKAnnotation protocol, and you won’t have anymore the problem of retreiving an annotation corresponding to an object, since that would be the same.

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

Sidebar

Related Questions

Im trying to pass multiple things from a webpage inside a UIWebView back to
I am trying to pass not only the dropdownlist ID using this, but I'm
I'm trying to pass context from one class to another.. pls tell me wat
When trying to pass a CGPoint to a method the point is passed, but
I'm trying pass in a url as a paramter to my controller like this:
Trying to pass the variable flickrurl to a PHP page with jQuery/ajax. It works
im trying to pass new query to FlexiGrid using this code: $('#fgAllPatients').flexReload({ query: 'blah=qweqweqwe'
Im trying to pass an array from javascript to java servlet using Jackson, how
Im trying to pass some variables from the URL to the PHP script. Now
Iam trying to pass dynamic argument values i.e username from request using spring ioc.But

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.