注释详细信息视图未在Mapkit中加载

时间:2011-07-02 03:58:40

标签: iphone uitabbarcontroller mapkit

我有一张地图,根据用户位置显示各种引脚。我可以毫无问题地查看引脚和标注。当我按下详细信息披露按钮时,我的MapDetailInfo不会加载。这是一些代码。

- (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 = MKPinAnnotationColorRed;
}
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];
}

不确定是否重要,但这是标签栏应用程序的一部分。任何帮助将非常感激。谢谢!

1 个答案:

答案 0 :(得分:0)

您正在实例化UINavigationController(UINavigationController *nav = [[UINavigationController alloc] init];),然后将新VC推送到其上,但您从未将该nav控制器添加到当前视图堆栈。简单地调用init不会将该导航控制器添加到堆栈中。

创建UITabController时,您可以为每个标签创建+使用导航控制器。然后将新VC推送到那个导航控制器。

希望这有帮助。

**编辑

如果您已经拥有所有标签的导航控制器,请将您的代码更改为:

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