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

发布于 2024-11-18 12:46:02 字数 1472 浏览 2 评论 0原文

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

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

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云淡月浅 2024-11-25 12:46:02

您正在实例化一个 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];
}

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];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文