开发者

Annotation Detail View not Loading in Mapkit

I have a Map that shows various pins based on the users location. I can view the pins and there callouts without a problem. When I press the detail disclosure button, my MapDetailInfo does not load. Here is some of the code.

- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>) annotation
{
// Specify which MKPinAnnotationView to use for each annotation. 

MKPinAnnotationView *businessListingPin = (MKPinAnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier: @"BLPin" ];

if (businessListingPin == nil)
{
    businessListingPin = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"BLPin"];
}
else
{
    businessListingPin.annotation = annotation;
}

// If the annotation is the user's location, don't show the callout and change the pin color
if(annotation == self.mapView.userLocation)
{
    businessListingPin.canShowCallout = NO;
    businessListingPin.pinColor = MK开发者_JAVA技巧PinAnnotationColorRed;
}
else
{
    businessListingPin.canShowCallout = YES;
    businessListingPin.pinColor = MKPinAnnotationColorPurple;
    businessListingPin.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];

}

return businessListingPin;
}

- (void)mapView:(MKMapView *)mapView 
 annotationView:(MKAnnotationView *)view 
calloutAccessoryControlTapped:(UIControl *)control
{
MapDetailInfo *abc = [[MapDetailInfo alloc]init];
UINavigationController *nav = [[UINavigationController alloc] init];
[nav pushViewController:abc animated:YES];
}

Not sure if it matters or not, but this is part of a tab bar application. Any help would be much appreciated. Thanks!


You are instantiating a UINavigationController (UINavigationController *nav = [[UINavigationController alloc] init];) and then pushing your new VC onto that, but you never add that nav controller to the current view stack. Simply calling init doesn't add that navigation controller to the stack.

When you create your UITabController, you can create + use a navigation controller for each tab. Then you push the new VC onto that navigation controller.

Hope this helps.

** edit

If you've already got navigation controllers for all of your tabs, change your code to this:

- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view 
calloutAccessoryControlTapped:(UIControl *)control
{
    MapDetailInfo *abc = [[MapDetailInfo alloc]init];
    [self.navigationController pushViewController:abc animated:YES];
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜