MKAnnotationView viewForAnnotation从未调用 [英] MKAnnotationView viewForAnnotation never called

查看:158
本文介绍了MKAnnotationView viewForAnnotation从未调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了2天的时间查找错误,我必须在这里要求帮助。我有MapViewController,并在地图上放置一些引脚。我复制了MapCallouts的大部分代码和AppleMap代码示例的WeatherMap。



无论如何,我似乎删除或错过了重要的部分。似乎MapViewController和以下代码之间没有连接

   - (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation :(id< MKAnnotation>)注释
{
NSLog(@MKAnnotationView);
return nil;
}

设置注释看起来像这样,它的效果很好:

   - (void)createPoi:(CLLocationCoordinate2D)theCoordinate 
{
NSLog(@createPoi);

RandomAnnotation * randomAnnotation = [[RandomAnnotation alloc] init];
[randomAnnotation setTheCoordinate:theCoordinate];
[randomAnnotation setTheTitle:@bla];
[randomAnnotation setTheSubTitle:@bla];
[self.mapAnnotations insertObject:randomAnnotation atIndex:kRandomAnnotationIndex];
[randomAnnotation release];
[self.mapView addAnnotation:[self.mapAnnotations objectAtIndex:kRandomAnnotationIndex]];
}

我不知道出了什么问题。有人可以给我一个提示什么是什么吗?我不得不承认,我没有任何代表模式的经验。

解决方案

确保地图视图的委托属性设置。



如果地图在IB中创建,请右键单击并将其代理插座文件的所有者。



如果地图是以代码创建的,则在创建地图视图后设置委托:

  mapView.delegate = self; 


after i spend 2 days of searching the bug i have to ask for help here. i do have MapViewController and place some pins on the map. i´ve copied most of the code from MapCallouts and WeatherMap of the apple code samples.

anyhow it seems that i´ve deleted or missed essential parts. it seems there is no connection between the MapViewController and the following code

- (MKAnnotationView *)mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>)annotation
{
    NSLog(@"MKAnnotationView");
    return nil;
}

setting an annotation looks like this and it works well:

- (void)createPoi:(CLLocationCoordinate2D)theCoordinate
{
    NSLog(@"createPoi");

    RandomAnnotation *randomAnnotation = [[RandomAnnotation alloc] init];
    [randomAnnotation setTheCoordinate:theCoordinate];
    [randomAnnotation setTheTitle:@"bla"];
    [randomAnnotation setTheSubTitle:@"bla"];
    [self.mapAnnotations insertObject:randomAnnotation atIndex:kRandomAnnotationIndex];
    [randomAnnotation release];
    [self.mapView addAnnotation:[self.mapAnnotations objectAtIndex:kRandomAnnotationIndex]];
}

i can´t figure out what's wrong. could anybody give me a hint what´s missing? i have to admit that i don´t have any experience with the delegate pattern.

解决方案

Make sure the map view's delegate property is set.

If the map is created in IB, right-click on it and hook up its delegate outlet to File's Owner.

If the map is created in code, set the delegate after creating the map view:

mapView.delegate = self;

这篇关于MKAnnotationView viewForAnnotation从未调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆