开发者

Trying to get a right callout button to load another view controller

I am creating a walking tour and am using mapkit. I have the map loading and am using custom icons as pins and loading my gps coordinates from a plist file. My callouts are working fine. My problem is that I would like the right callout button to load different information on another screen for each stop (picture of stop and an MP3). Would I load a different view 开发者_Python百科controller for each stop on the tour? If so what code would I add to this following to have a view controller named Detailcontroller load?

 - (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
    NSLog(@"I've been tapped");
}

If I am way off and someone could point me in the right direction it would be greatly appreciated. I apologize for my wording as I am really new to coding/app development.


I would hope and expect that you'd use the same kind of view controller for each stop, but set up with different data. When I've done something like this, my annotations have been the data objects for each point of interest on the map, so I'd do this:

-(void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
    StopInfo *stopInfo = view.annotation;
    StopInfoDetailController *detailController = [[StopInfoDetailController alloc] initWithNibName:nil bundle:nil];
    detailController.stopInfo = stopInfo;
    [mapView.navigationController pushViewController:detailController animated:YES];
    [detailController release];
}

In this case, StopInfo would be the class of the annotation objects. It should contain the information that the detail controller needs to do it's thing: MP3 file name, stop location, stop image file name, stop description, etc.

Note that you might actually have several different kinds of annotations on your map. Maybe some are stops on your walking tour while others are points of interest that aren't on the tour, food vendors, bathrooms, etc. In that case you might want to use different view controllers for each type of anntation, so you'd look at the annotation object to figure out what kind of view controller to instantiate.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜