未在Mapkit中加载注释局部视图



我有一个Map,它根据用户的位置显示各种引脚。我可以毫无问题地查看针脚和标注。当我按下详细信息公开按钮时,我的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];
}

不确定它是否重要,但这是选项卡栏应用程序的一部分。任何帮助都将不胜感激。谢谢

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

当你创建UITabController时,你可以为每个选项卡创建+使用一个导航控制器。然后你把新的VC推到那个导航控制器上。

希望这能有所帮助。

**编辑

如果你已经为所有标签设置了导航控制器,请将代码更改为:

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

最新更新