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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:53:46+00:00 2026-06-15T08:53:46+00:00

So in my app, I have a mapView that drops pins when the screen

  • 0

So in my app, I have a mapView that drops pins when the screen is pressed. Once the annotations are dropped, they are placed into an array. There will be multiple pins on the map at one time, and each pin has a identifier property that is an NSNumber. I have another view controller that is pushed onto the stack when the callout button on the annotationView is pressed, and this view has a button that I want to delete the pin from the mapView when pressed. My problem is, I do not know how to pass the identifier of the pin to the second view controller. Here is some code.

This is the method where I drop the pin:

-(void)press:(UILongPressGestureRecognizer *)recognizer
{
  CGPoint touchPoint = [recognizer locationInView:_worldView];
  CLLocationCoordinate2D touchMapCoordinate = [_worldView convertPoint:touchPoint toCoordinateFromView:_worldView];

geocoder = [[CLGeocoder alloc]init];
CLLocation *location = [[CLLocation alloc]initWithCoordinate:touchMapCoordinate
                                                    altitude:CLLocationDistanceMax
                                          horizontalAccuracy:kCLLocationAccuracyBest
                                            verticalAccuracy:kCLLocationAccuracyBest
                                                   timestamp:[NSDate date]];
[geocoder reverseGeocodeLocation:location
               completionHandler:^(NSArray *placemarks, NSError *error) {
                   NSLog(@"reverseGeocoder:completionHandler: called");
                   if (error) {
                       NSLog(@"Geocoder failed with error: %@", error);
                   } else {
                       CLPlacemark *place = [placemarks objectAtIndex:0];
                       geocodedAddress = [NSString stringWithFormat:@"%@ %@, %@ %@", [place subThoroughfare], [place thoroughfare], [place locality], [place administrativeArea]];
                       if (UIGestureRecognizerStateBegan == [recognizer state]) {
                           value = [number intValue];
                           number = [NSNumber numberWithInt:value + 1];
                           addressPin = [[MapPoint alloc]initWithAddress:geocodedAddress coordinate:touchMapCoordinate
                                                                   title:geocodedAddress identifier:number];
                           NSLog(@"The identifier is %@", number);
                           [_annotationArray addObject:addressPin];
                           [_worldView addAnnotation:addressPin];
                           NSLog(@"The number of pins in the annotation array is: %u",_annotationArray.count);
                       }
                   }
               }];
}

This is where I create the second view controller:

-(void)mapView:(MKMapView *)mapView
annotationView:(MKAnnotationView *)view
calloutAccessoryControlTapped:(UIControl *)control
{
  PinViewController *pinViewController = [[PinViewController alloc]init];
  [[self navigationController]pushViewController:pinViewController animated:YES];

  pinViewController.label.text = view.annotation.title;
}

Here is my MKAnnotation class:

#import <CoreLocation/CoreLocation.h>
#import <MapKit/MapKit.h>

@interface MapPoint : NSObject <MKAnnotation>
{
NSString *_address;
CLLocationCoordinate2D _coordinate;
NSNumber *_identifier;
}

- (id)initWithAddress:(NSString*)address
    coordinate:(CLLocationCoordinate2D)coordinate
         title:(NSString *)t
    identifier:(NSNumber *)ident;


//This is a required property from MKAnnotation
@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;

//This is an optional property from MKAnnotataion
@property (nonatomic, copy) NSString *title;
@property (nonatomic, readonly, copy) NSString *subtitle;
@property (nonatomic) BOOL animatesDrop;
@property (nonatomic) BOOL canShowCallout;

@property (copy) NSString *address;
@property (copy, nonatomic) NSNumber *identifier;

@end

#import "MapPoint.h"

@implementation MapPoint

@synthesize title, subtitle, animatesDrop, canShowCallout;
@synthesize address = _address, coordinate = _coordinate, identifier = _identifier;

-(id)initWithAddress:(NSString *)address
   coordinate:(CLLocationCoordinate2D)coordinate
        title:(NSString *)t
   identifier:(NSNumber *)ident
{
self = [super init];

if (self) {
    _address = [address copy];
    _coordinate = coordinate;
    _identifier = ident;

    [self setTitle:t];

    NSDate *theDate = [NSDate date];

    subtitle = [NSDateFormatter localizedStringFromDate:theDate
                                              dateStyle:NSDateFormatterMediumStyle
                                              timeStyle:NSDateFormatterMediumStyle];
    }
return self;
}


@end
  • 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-15T08:53:48+00:00Added an answer on June 15, 2026 at 8:53 am

    Try following:

    - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
        MyAnnotation *myAnnotation = view.annotation;
    }
    

    Just add it as a property in your SecondViewController:

    -(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
    {
      PinViewController *pinViewController = [[PinViewController alloc]init];
      [[self navigationController]pushViewController:pinViewController animated:YES];
    
      pinViewController.label.text = view.annotation.title;
      pinViewController.annotation_id = view.annotation.some_id; 
    }
    

    Add segue from your first ViewController Try to second ViewController and do check your class like following:

    - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control {
        [self performSegueWithIdentifier: @"segue_name" sender: view];
    }
    
    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    
        if([segue.identifier isEqualToString: @"segue_name"]) {
            SecondViewController *vc = segue.destinationViewController;
            vc.variable_name = view.annotation.title;
           MyAnnotation vc.annotation_id*myAnnotation = view.annotation.some_id;
        }annotation;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an app that has a mapview, and it shows 20 pins (from
In my app, I have a mapView that drops a pin with a UILongPressGestureRecognizer.
I have a mapview that displays locations of cash points. Annotations are dropped and
My app have a background image that fills the screen. I'd like to display
I have a small app that from the home screen has a few buttons,
Imagine that I have a camera app where I show a small MapView in
I have an Android app that when launched, inflates a MapView, gets the user's
I'm developing on an app that is location-based, I have a mapView set to
I have an app, that uses mapview. i can only see the map, when
I have an android app that takes an array from a website {d:[{latitude:-1.0,longitude:-1.0,time:07:14 PM

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.