Question

I am making an App that shows annotations on a map using the iOS MapKit. When a user taps an annotation the callout window pops up and shows the Tile, Subtitle and a Detail Disclosure Button. I need to have additional information popup when the user taps the Detail Disclosure Button.

This additional information could be a pop-up window or some other view that gets loaded. I am trying to figure out how best to do this.

Right now I have the Detail Disclosure Button added by using the following code in my annotationView implementation file. Note the line self.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure]...and also note that it is being done for THREE annotationTypes:

Here is where it is added:

- (id)initWithAnnotation:(id<MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier
{

    iCodeBlogAnnotation *myAnnotation = (iCodeBlogAnnotation*)annotation;

    // setup the if/else statements

    if ([myAnnotation annotationType] == iCodeBlogAnnotationTypeHotels)

    {

        self = [super initWithAnnotation:myAnnotation reuseIdentifier:reuseIdentifier];
        self.frame = CGRectMake(0, 0, kWidth, kHeight);
        self.backgroundColor = [UIColor clearColor];

        self.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];


        imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Hotel.png"]];
        imageView.frame = CGRectMake(kBorder, kBorder, kWidth - 2 * kBorder, kWidth - 2 * kBorder);
        [self addSubview:imageView];



    }

    else if([myAnnotation annotationType] == iCodeBlogAnnotationTypeAerialShots)

    {

        self = [super initWithAnnotation:myAnnotation reuseIdentifier:reuseIdentifier];
        self.frame = CGRectMake(0, 0, kWidth, kHeight);
        self.backgroundColor = [UIColor clearColor];

         self.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];


        imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"StreetView.jpg"]];
        imageView.frame = CGRectMake(kBorder, kBorder, kWidth - 2 * kBorder, kWidth - 2 * kBorder);
        [self addSubview:imageView];



    }

    else if ([myAnnotation annotationType] == iCodeBlogAnnotationTypeStreets)

    {
        self = [super initWithAnnotation:myAnnotation reuseIdentifier:reuseIdentifier];
        self.frame = CGRectMake(0, 0, kWidth, kHeight);
        self.backgroundColor = [UIColor clearColor];

        self.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];


        imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Street.png"]];
        imageView.frame = CGRectMake(kBorder, kBorder, kWidth - 2 * kBorder, kWidth - 2 * kBorder);
        [self addSubview:imageView];


    }

Then, in my viewController implementation file I have the following method to detect when the user has tapped the detail disclosure button:

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

{
    // add code here for what you want to do

}

What code should I add to the above method in order to load some new pop-up window or new view which would hold the detailed information?

I tried creating a new detailedViewController class and adding the following code to the "add code here" in the above controllTapped method:

iCodeBlogMapDetailViewController *dvc = [[iCodeBlogMapDetailViewController alloc] init];
[self.navigationController pushViewController:dvc animated:YES];

but nothing happens.

What would be my next step?

Thank you,

No correct solution

OTHER TIPS

Make sure your Controller implements MKMapViewDelegate and set the MKMapView's delegate to the controller.

You have to use MKMapView delegate method for this purpose like following, for identifying your iCodeBlogAnnotation:

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
    id <MKAnnotation> annotation = [view annotation];
    if ([annotation isKindOfClass:[iCodeBlogAnnotation class]])
    {
        iCodeBlogMapDetailViewController *dvc = [[iCodeBlogMapDetailViewController alloc] init];
        [self.navigationController pushViewController:dvc animated:YES];        
    }
}

Let me know, If you get it to work

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top