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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:47:04+00:00 2026-05-20T12:47:04+00:00

I have declared the following in my .h file: Annotation *annoForMoreDetails . However when

  • 0

I have declared the following in my .h file:

Annotation *annoForMoreDetails.

However when I try to set it to the current annotation in the method

- (MKAnnotationView *)mapView:(MKMapView *)mapViews viewForAnnotation:(id <MKAnnotation> )annotation

It gets set to the wrong object.

Here is my code:

 - (MKAnnotationView *)mapView:(MKMapView *)mapViews viewForAnnotation:(id <MKAnnotation> )annotation
{
    NSLog(@"welcome into the map view annotation");
    // if it's the user location, just return nil.
    if ([annotation isKindOfClass:[MKUserLocation class]])
        return nil;
    for (annotation in [mapView annotations]) {
        if ([[mapView annotations] containsObject:annotation]) {
            annoForMoreDetails = annotation;
        }
    }
    if (annoForMoreDetails.coordinate.latitude != mapViews.userLocation.coordinate.latitude && annoForMoreDetails.coordinate.longitude != mapViews.userLocation.coordinate.longitude) {
    // try to dequeue an existing pin view first
    static NSString* AnnotationIdentifier = @"AnnotationIdentifier";
    MKPinAnnotationView* pinView = [[[MKPinAnnotationView alloc]
                                     initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier] autorelease];
    pinView.animatesDrop=YES;
    pinView.canShowCallout=YES;
    pinView.pinColor = MKPinAnnotationColorGreen;

    UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
    [rightButton setTitle:annotation.title forState:UIControlStateNormal];
    [rightButton addTarget:self
                    action:@selector(moreDetails)
          forControlEvents:UIControlEventTouchUpInside];
    pinView.rightCalloutAccessoryView = rightButton;
    return pinView;
    }
    else if (annoForMoreDetails.coordinate.latitude == mapViews.userLocation.coordinate.latitude && annoForMoreDetails.coordinate.longitude == mapViews.userLocation.coordinate.longitude) {
        return nil;
    }
    return nil;
}

- (void)moreDetails {
    annotationCalloutView.frame = CGRectMake(70, 120, 188, 218);
    annotationCalloutView.alpha = 0.0;
    mapView.userInteractionEnabled = NO;
    annotationCalloutView.userInteractionEnabled = YES;
    titleLabel.text = annoForMoreDetails.title;
    titleLabel.numberOfLines = 0;
    titleLabel.userInteractionEnabled = NO;
    addressLabel.text = annoForMoreDetails.subtitle;
    [self.view addSubview:annotationCalloutView];
    [UIView beginAnimations:@"callout" context:NULL];
    [UIView setAnimationDuration:0.6];
    annotationCalloutView.alpha = 1.0;
    [UIView commitAnimations];
}

If you see anything wrong please point it out!

  • 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-20T12:47:05+00:00Added an answer on May 20, 2026 at 12:47 pm

    Are you trying to use annoForMoreDetails to know which annotation the user tapped on so you can show more details? If that’s the case, there’s an easier way. Use the map view’s calloutAccessoryControlTapped delegate method. It will be called when the user taps on the accessory button and it will pass the annotation view which includes the annotation as a property.

    Remove the annoForMoreDetails instance variable and in viewForAnnotation, remove the for-loop that sets annoForMoreDetails (I think it ends up setting it to the last annotation every time). Remove all other references to annoForMoreDetails.

    Also in viewForAnnotation, remove the addTarget line on the rightButton since you’ll replace your custom moreDetails method with an implementation of calloutAccessoryControlTapped:

    - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view 
        calloutAccessoryControlTapped:(UIControl *)control
    {
        Annotation *annoForMoreDetails = (Annotation *)view.annotation;
    
        //the code currently in moreDetails method goes here...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following template method declared in my interface: class IObjectFactory { public:
I have the following declared in my spring security configuration file ( http://www.springframework.org/schema/security/spring-security-2.0.1.xsd ):
I have the following array declared inside a header file. static const float elementsArray[300]
I have declared the following variable outside of an external js file because part
I have declared the following struct: typedef struct _RECOGNITIONRESULT { int begin_time_ms, end_time_ms; char*
In following program . I have one doubt. I have declared one global variable
I have the following enum declared: public enum TransactionTypeCode { Shipment = 'S', Receipt
I have a project that requires the following. Four arrays will be declared in
I have the following code: DECLARE @testDate date --SET @testDate=dateadd(wk, 5830, 0) SET @testDate='2011-09-26
I have the following query: DECLARE @Region VARCHAR(MAX) SET @Region = '' SELECT @Region

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.